# approximating euler's number

This is a discussion on approximating euler's number within the C Programming forums, part of the General Programming Boards category; Hi, I am a newbie and I need some help with this one... e = 1 + 1/1! + 1/2! ...

1. ## approximating euler's number

Hi,
I am a newbie and I need some help with this one...

e = 1 + 1/1! + 1/2! + 1/3! + 1/4! + 1/5! .......... 1/(n-1)! + 1/(n!)

I need to approximate the euler's value, I want to know what should my for loop look like?

2. Write it out as a summation and you're halfway there.

3. This is what I have, but I am getting a logical error.
Code:
```n = getN();

for (i = n; i > 0; i--)
sum += (1/(float) i);

printf( "Sum = %f\n", (sum + 1));
return 0;```

4. Please use code tags when you post code

5. > sum += (1/(float) i);
You want something like
sum += (1/ factorial(i) );

Read the formula, then write the code.

6. As a bookkeeping, I believe that e is actually known as Napier's constant. It was only named e in honor of Euler.