void main() { double sum=0; for(int i=0;;i++) { double term=1.0/(2*i+1); if(i%2==0) sum=sum+term; else sum=sum-term; if(term<1e-6)break; } printf("%.2f",sum); }
#include<stdio.h> void main() { double sum=0; int flag=1; int a=0; double term=1.0/(2*a+1); while(term>1e-6) { term=1.0/(2*a+1); sum=sum+term*flag; a++; flag=-flag; } printf("%.2f",sum); }