输出结果为1.718279,但我输出1.718282,该怎么改

img


#include <stdio.h>
#include <math.h>
main()
{
int n = 1;
double s = 0,t = 1;
while(fabs(t) >= 1e-5)
{
t = t / n;
s = s + t;
n++;
}
printf("%f",s);
}

你改成%.6lf试试看

你把while循环里面的三局话复制一次放到while循环前应该就可以了