习题二 5
#include<stdio.h> int main(void) { int i,n,numerator,denominator,flag; double sum,item; printf("Enter n:"); scanf("%d",&n); numerator=1; denominator=1; sum=0; flag=1; for(i=1;i<=n;i++){ item=flag*(numerator*1.0/denominator); numerator=numerator+1; denominator=denominator+2; flag=-flag; sum=sum+item; } printf("sum=%lf\n",sum); return 0; }
循环 还是不怎么会