Home > Back-end >  Write the code (best can explain ideas)
Write the code (best can explain ideas)

Time:05-01

E approximation, e material 1 + 1/1! + 1/2! + a third! +... + 1/n! Calculating various kinds of, until the last item value is less than 10 (4) (calculation items are greater than or equal to 10 (4))

CodePudding user response:

Reference:
 # include 

Double fun_e ()
{
Double sum=1;//first set to 1
Double temp=1;
int i=1;
While (temp> E=1-4) {//the last item value is less than 10 (4)
Temp=temp/I;//the second 1/1, namely 1/1! ; 1/2, the third is 1/2. ; Item 4 (1/2)/3, namely a third! .
Sum=sum + temp;//[sum=1 + 1/1 + 1/2! + 1/3! + 1/4!! + 1/5 +... + 1/n!]
i++;
}
return sum;//return the sum
}

Int main ()
{
Double e=fun_e ();
Printf (" e=% lf \ n ", e);

return 0;
}
  • Related