
Euler's number question
Hello, I am having a problem with my following lab assignment. I’ve included what I’ve completed so far. I am not sure if it is correct. If anyone can help me out, I would greatly appreciate it.
This is the problem in question:
Euler's number, "e" is used as the basic of natural logarithms. It can be approximated using the following formula:
e = 1 + 1/1! + 1/2! + 1/3! + 1/4! 1/5! + 1/6! + ... + 1/(n1)! + 1/n!
Write a program that approximates "e" using a loop that terminates when difference between two successive values of "e" differ by less than 0.0000001.
This is what I’ve started/completed so far.
***start***
main()
{
/*repeat until euler(n)  euler(n1)<=0.0000001 */
}
float euler(int n)
{
if(n==0)
return 1;
else
return (1/factorial(n) + euler(n1));
}
int factorial(int n)
{
.
.
.
}
***is this correct?***
euler(0) => 1
euler(1) => 1/1! + euler(0)
1/1! + 1
euler(2) => 1/2! + euler(1)
1/2! + 1/1! + 1
euler(3) => 1/3! + euler(2)
1/3! + 1/2! + 1/1! + 1
euler(4) => 1/4! + 1/3! + 1/2! + 1/1! + 1
1/4! + euler(3)
***end***

Don't do it recursivly. Have a running sum, add 1/k! to the sum and then if 1/k! is less than 0.0000001 stop else repeat.

I am still not sure how to pill this all together...

It is correct. I understand you need help with the factorial? I saw you understand recursion, so the factorial shouldn't be too hard.
Factorial:
n! = n x (n  1) x (n  2) x ... x 3 x 2 x 1
So the endstep is 1 and the recursion step is n x (n  1).
Code:
int fac (int n)
{
if (n == 1)
return 1;
else
return (n * fac (n  1));
}