0

Hi guys. I'm pretty new to C program. I've been given this assignment to write a program that asks the user thow many terms of the serires equation to use in approximating PI. The formula given is pi=4X(1- 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 - ....)

Here is the script that I've written but I'm stuck. Please advice. My alogarithm might be wrong

```
#include <stdio.h>
int main (void)
{
int x,
i;
//int sum=0;
double PI;
float sum=0, y;
printf("Please enter the terms of series that should be included> ");
scanf("%d", &x);
for (i=1; i<=x; i++){
i=y;
if (i%2==1) //odd
if (sum%2==0)
sum=sum+1/y;
else
sum=sum-1/y;
}
PI= 4*sum;
printf("The sum is %f\n", sum);
printf("Approximate value of PI is %f\n", PI);
return 0;
}
```