计算e的近似值,直到最后一项小于10^-6
#include<stdio.h>#include<stdlib.h>
int main()
{
double i = 0, x = 0,m=0;
double sum = 1, k = 1;
do
x++;
while ((1.0 / x) < 0.000001);
for (i = 1; i <= x; i++)
{
k = k* i;
sum += 1.00 / k;
}
printf("e≈%.9f", sum);
system("pause");
return 0;
}
为什么结果总是2.00000000