写C语言代码计算1-(1)/(2)+(1)/(3)-(1)/(4)+⋯+(1)/(99)-(1)/(100)
时间: 2023-10-18 10:05:35 浏览: 102
#include<stdio.h>
int main(){
float sum = 1.0;
int i;
for(i = 2; i <= 100; i++){
if(i%2 == 0){
sum -= 1.0/i;
}else{
sum += 1.0/i;
}
}
printf("%.6f", sum);
return 0;
}
阅读全文