int main()
{
int i = 0;
int flag = 1;
double sum=0.0;//计算结果为小数,赋值应为小数;
double sum1 = 0.0;
double sum2 = 0.0;
for (i = 1; i <= 100; i++)
{
/*sum += flag * (1.0 / i);//计算结果为小数,赋值应为小数;
flag = -flag;*///简洁的算法
if (i % 2 == 0)
sum1 += 1.0 / i;//计算结果为小数,赋值应为小数;
if (i % 2 != 0)
sum2 += 1.0 / i;//计算结果为小数,赋值应为小数;
}
sum = sum2 - sum1;
printf("%lf", sum);
return 0;
}