Home › Forums › C Programming › Approximate the value of PI › Reply To: Approximate the value of PI

September 4, 2008 at 5:32 am
#3447

RandiHoltermann

Participant

Thanks for your input. The following is the working scripts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <stdio.h><br /> int main (void)<br /> {<br /> int x;<br /> float sum=0;<br /> double PI;<br /> <br /> printf("Please enter the terms of series that should be included> ");<br /> scanf("%d", &x);<br /> <br /> for (int i=1; i<x; i+=2)<br /> if (i%4==1)<br /> sum=sum+1./(double)i;<br /> else<br /> sum=sum-1./(double)i;<br /> <br /> PI= 4*sum;<br /> printf("The sum is %fn", sum);<br /> printf("Approximate value of PI is %fn", PI);<br /> <br /> return 0;<br /> } |