> 其他 >
一道C语言程序题
e约定于1+1/2!+ 1/3!+.+1/n!
计算前20项;
计算各项,知道小于10^-4为止;
人气:107 ℃ 时间:2020-08-31 04:52:25
解答
请楼主参考,希望有用
#include "stdio.h"
void main(void)
{
double value = 0;
double current = 1;
int i;
for(i=1; i 1e-4; i++)
{
current /= i;
value += current;
}
printf("when it's less than 1e-4, n = %d, value of E is %f\n", i-1, value);
}
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版