You're close.
(1) half point
The denominator changes each term by multiplication. Look again at the table:
term number: 1 2 3 4
denominator value: 1 1*2 1*2*3 1*2*3*4 |
What happens to the denominator each time through the loop (after ++term_number)?
(2) no point
Each
term is a fraction like 1/2 (==0.5) and 1/120 (==0.0083). Are these values integers? (No.) The only two terms representable as integers are 1/0! (==1) and 1/1! (==1). All other terms are double. (Use doubles.)
(3) half point
The loop represents addition,
not the sum.
Each time through the loop represents a
single term of that sum.
(4) no point (sorry)
The value of
e is incrementally built.
The initial value for
e is given before we enter the loop:
double e = 1.0;
.
Obviously, 1 is a very bad approximation for
e. So we enter our loop and compute the next
term of our approximation: 1/1! == 1. Adding that to our current
e gives us an approximation of e==2.
That's better, but still not very accurate. So we enter the loop again and compute the next term of our approximation: 1/2! == 0.5. Adding that to our current
e gives us an approximation of e==2.5.
Much better! Still, we'd like to do better. So we enter the loop again and compute the next term as 1/3! == 1/(3*2) == 0.16666.... Adding that to our current
e gives us e==2.66666....
Next term is 1/4! == 1/(4*3*2) == 0.041666666....
Next term is 1/5! == 1/(5*4*3*2) == 0.008333333...
Each time through the loop, we add a smaller and smaller number to
e. Eventually we'll have looped enough times that
e has enough correct digits that we can consider it close enough.
Each of these questions is designed to help you see how it
works. Correct your conceptual understanding, and you'll have an easier time with the loop itself.
Try again and post back. (Don't give up!)
[edit]
Since you seem to be weak on the idea of summation, I found something that might help.
http://www.coolmath.com/algebra/19-sequences-series/03-series-sigma-notation-01.htm
Coolmath is a pretty good website for basic concepts.