1-1/2+1/3-1/4+1/5+…+1/99-1/100 c语言编程
1-1/2+1/3-1/4+1/5+…+1/99-1/100 c语言编程
日期:2018-01-10 22:01:24 人气:1
/*不对,你可以参考下面的*/
#include
main()
{
int i = 1;
double s, t = 0;
for (i = 1; i <= 100; i++) {
s = 1.0 / i;
if (i % 2 == 0)
t -= s;
else
t += s;
}
printf("%.4lf\n", t);
}