June 29th, 2013, 07:57 PM
Using a loop to find the value of 'e'
The value of e can be found by this infinite series:
"1 + 1/1! + 1/2! +... +1/n!"
n will be provided as an input. The program will do the rest of the job. Any idea how to set up the algorithm?
June 29th, 2013, 11:56 PM
I'd take the input as a command line argument.
int main(int ac,char*av)
I'd verify the input.
Although the input isn't really all that important. So you might just as well bind whatever the values are to a reasonable range, say, 1 to 24 terms. The reciprocal of factorial 23 (in j: ) won't contribute to a double precision value. Next I'd compute the reciprocals of the factorials into an array, successively. You know the maximum array size because you limited n. These I'd add from smallest to largest, and finally print the result to 18 figures. All-in-all, n-1 divisions and additions.
if ((ac < 2) || (sscanf(av, "%d", &n) != 1))
I checked to see if the addition order influences the least significant digit. It does, with the result that adding in my suggested order is closer to Euler's constant.
[/code] are essential for python code and Makefiles!