| |
Design due at Fleck's office at noon on Saturday, 2, 1999
Code must be submitted by 8:00 AM on Monday, October 4, 1999
In this assignment you will use for loops to compute some simple
mathematical functions.
Note: The purpose of this assignment is to do the computations using only
primitive arithmetic. Do not call any functions from the Math
package.
- The value of
e (the base of the natural logarithms)
raised to any number (floating point or integer) x can be
computed by the series:
1 2 3 4
x x x x x
e = 1 + ---- + ---- + ---- + ---- + ...
1! 2! 3! 4!
You must write a program ApproxE which uses this series to
approximate the value of e raised to a given power.
Ask the user for the a floating point (double)
value for the exponent x. Also ask them for an
integer (int) value n, the number
of terms of the expansion they want you to compute.
Compute the sum of that many terms of the expansion and print
the result for the user.
The number of terms obtained from the user does not include the
initial 1. So if the user asks for two terms, you would
compute:
1 2
x x x
e = 1 + ---- + ----
1! 2!
- Write a program DisplayPrimes which asks the user for a number and
displays all the prime numbers up to (and, possibly, including) that
number. (Note that 1 is not considered a prime number.)
|