#include<stdlib.h>
#include<stdio.h>
long double fact(unsigned long int n)
/*The factorial of a positive integer by recursion*/
{
if (n==0)
return 1;
else
return n*fact(n-1);
}
int main()
{
long double sum, n;
int i, m;
printf("\t/*Code to find the approximate value of e */");
check:
printf("\n\n\tPlease Enter the value of n := ");
scanf("%lf", &n);
sum=0;
for (i=0; i<=n; i++)
sum +=1/(fact(i));
printf("\n\n\tThe appriximate value of e := %.15lg\n\n\t", sum);
printf("Let's do this again? 1/ YES Any key/ NO := ");
scanf("%d", &m);
if (m==1)
goto check;
else (1);
return 0;
}
此代码在 Visual C++ 2010 中运行良好,但不适用于 DEV C++。对于 e 的值,它一直返回零。有人可以解释为什么!谢谢!