/*计算数列之和*/ #include<stdio.h> int main(void) { int denominator,molecule,flag ,i,n;/*denomiator为分母,molecule为分子,flag代表符号*/ double item,sum; printf("Enter n:");/*输入提示*/ scanf("%d",&n); flag=1;/*令起始的符号为正数*/ denominator=1; sum=0; molecule=1; for(i=1;i<=n;i++){ item=flag*molecule*1.0/denominator; sum=sum+item; flag=-flag; denominator=denominator+2; molecule=molecule+1; } printf("sum=%f ",sum); return 0; }