As I'm informed about the rules, I won't ask you to write all of the code.. The problem i am trying to overcome is that:
Write a program that approximates e by computing the value of :
e=1+1/1!+1/2!+1/3!....+1/n! (user will enter the value "n")
So, my code is as it's written below;
But results are not satisfying when i execute the program.. I ask you to find my mistake and inform me about it. Thanx.
Code:
#include <stdio.h>
int main ()
{
int k, n, x;
float total, denom;
scanf("%d", &n);
k=1;
denom=1;
total=1;
while(n>=k){
x=n;
for(;x>0; x--){
denom=denom*x;
}
total+=1.0f/denom;
n--;
}
printf("Result:%.4f\n", total);
return 0;
}