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

#3447
RandiHoltermann
Participant

Thanks for your input. The following is the working scripts

    #include 
int main (void)
{
int x;
float sum=0;
double PI;

printf("Please enter the terms of series that should be included> ");
scanf("%d", &x);

for (int i=1; i if (i%4==1)
sum=sum+1./(double)i;
else
sum=sum-1./(double)i;

PI= 4*sum;
printf("The sum is %fn", sum);
printf("Approximate value of PI is %fn", PI);

return 0;
}