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!)
my answer
can any one tell what is wrong here?Code:#include <stdio.h>
int main()
{
int factorial=1;
float formula;
int counter=0;
float e=0.0;
while(counter<=5)
{
if(counter==0){factorial=1;
counter=counter+1;}
factorial*=counter;
formula=(float)counter/factorial;
e=e+formula;
counter++;
}
printf("%f",e);
return 0;
}