help with a c code
the question is
Write a program that estimates then prints the value of the mathematical constant e by using the formula:
e=1+ 1/1!+ 2/2! + 3/3!+ ...
(calculate till 5/5!)
can any one tell what is wrong here?
You don't indent your code.
Originally Posted by hula2007
You need to tell us what's wrong. Do you get an error, a wrong result, ...?
you are incrementing counter twice in the first iteration of the loop but as you are checking <= you get away with that, you dont need to assigin 1 to factorial in the IF statement as it was assigned 1 to start with and the WHILE control is not repeated (which would mean reassignment was neccesary) Your program is a bit clunky and could be cleaner, certainly better formatted, but apart from that it should work ok
Sorry but i dont really understand maths notation, wish i did..dont know what the ! means so i cant figure out your description of the formula relative to the code and tell you if there is a problem, but it could certainly be expressed with one line using appropriate parentheses to get the order right.
It probably doesn't help that your mathematical description is wrong. I haven't even checked to see if the code matches the formula.
e = 1 + 1/1! + 1/2! + 1/3! + ..... not 1 + 1/1! + 2/2! + 3/3! + .....