2025-03-06 22:46:33 +08:00

26 lines
424 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*-------------------------------------------------------
编程计算求e近似值
用while语句求直到最后一项值小于10-5为止。
e=0+1+1/1+1/1/2+1/1/2/3...
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i;
double t,e;
i=1;
t=1.0;
e=0;
/**********Program**********/
e = 2;
i = 2;
while(t/i > 1e-5){
e += t/i;
t /= i++;
}
/********** End **********/
printf("e=%f\n",e);
}