#include<stdio.h>
#include<stdlib.h>
int main() {
int flag=1;
double tmp = 1;
double sum = 0;
int i;
for (i = 1;i <= 100;i++) {
tmp=1.0/i*flag;
sum = sum + tmp;
flag *= -1;
}
printf("%lf\n", sum);
system("pause");
return 0;
}
计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
最新推荐文章于 2023-07-24 20:43:07 发布