#includeint main(){ int i,n,flag,a; double sum,item; printf("Enter n:"); scanf("%d",&n); flag=1; a=1; sum=0; for(i=1;i<=n;i++){ item=flag*1.0/a; sum=sum+item; flag=-flag; a=a+2; } printf("result=%.4f\n",sum); return 0;}
本文共 338 字,大约阅读时间需要 1 分钟。
#includeint main(){ int i,n,flag,a; double sum,item; printf("Enter n:"); scanf("%d",&n); flag=1; a=1; sum=0; for(i=1;i<=n;i++){ item=flag*1.0/a; sum=sum+item; flag=-flag; a=a+2; } printf("result=%.4f\n",sum); return 0;}
转载于:https://www.cnblogs.com/reaper/p/3378772.html