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?
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?
Write it out as a summation and you're halfway there.
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;
Last edited by Salem; 10-26-2006 at 05:28 AM. Reason: Added code tags
Please use code tags when you post code
> sum += (1/(float) i);
You want something like
sum += (1/ factorial(i) );
Read the formula, then write the code.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
As a bookkeeping, I believe that e is actually known as Napier's constant. It was only named e in honor of Euler.
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction