#include<stdio.h>intmain(){int i =0;double sum =0;int flag =1;for(i =1; i <=100; i++){
sum += flag *1.0/ i;
flag =-flag;//通过flag,可以使数在正负数之间交替}printf("%lf",sum);return0;}
#include<stdio.h>intmain(){int i =0;double sum =0;//遍历1~100for(i =1; i <=100; i++){//判断当前数是奇数或偶数if(i %2==1){//i为奇数,将sum加上1/i的值
sum +=1.0/ i;}else{//i为偶数,将sum减去1/i的值
sum -=1.0/ i;}}printf("%lf\n", sum);return0;}