//e = 1/1 + 1/1! + 1/2! + 1+3!...当最后一项小于1e-10结束
#include<stdio.h>
#include<Windows.h>
int main()
{
float result = 1, temp = 1, temp1 = 0;
int i=1;
do
{
temp *= i;
temp1 = 1/temp;
result += temp1;
i++;
printf("%.2f/%.2f %.2f\n",1.0,temp,result);
}while(temp1>1e-10);
system("pause");
return 0;
}
输出如下1.00/1.00 2.00
1.00/2.00 2.50
1.00/6.00 2.67
1.00/24.00 2.71
1.00/120.00 2.72
1.00/720.00 2.72
1.00/5040.00 2.72
1.00/40320.00 2.72
1.00/362880.00 2.72
1.00/3628800.00 2.72
1.00/39916800.00 2.72
1.00/479001600.00 2.72
1.00/6227020800.00 2.72
1.00/87178289152.00 2.72
|