首页 > 编程语言 >程序:计算1/1-1/2+1/3......-1/100

程序:计算1/1-1/2+1/3......-1/100

时间:2023-01-21 15:32:08浏览次数:53  
标签:lf 1.0 int double sum 程序 ......- flag 100


#include<stdio.h>
int main()
{
int i = 1;
int flag = 1;
double sum = 0;
for (i = 1; i <= 100; i++)
{
sum += flag * (1.0 / i);
flag = -flag;
}
printf("总共的和为%lf", sum);
return 0;
}


程序:计算1/1-1/2+1/3......-1/100_i++

标签:lf,1.0,int,double,sum,程序,......-,flag,100
From: https://blog.51cto.com/u_15923331/6021179

相关文章