用C语言编写程序:1-1/2+1/3-1/4+1/5......+1/99-1/100
时间: 2023-10-05 21:08:00 浏览: 88
C#求1-1/2+1/3-1/4+…….-1/100的值
#include <stdio.h>
int main() {
double sum = 0.0;
int i;
for(i=1; i<=100; i++) {
if(i%2 == 0) {
sum -= 1.0/i;
} else {
sum += 1.0/i;
}
}
printf("%.2f", sum);
return 0;
}
阅读全文