[code]
THe value for PI can be determined by the series equation
PI= 4x (1-1/3+1/5-1/7+1/9-1/11+1/13-...)
write a program to approximate the value of PI using the formula given including terms up through 1/99.
I wrote this code but not sure what I am doing wrong. please some one help.
thanks
Code:
#include <stdio.h>
#include <math.h>
int
main(void)
{
double x, y, z, sum, pi, i, n;
sum = 1.0;
for (i = 0, y = 3.0; i < n; ++i, y += 2.0)
{
z = 1.0 / y;
if ((i & 1) == 0)
sum -= z;
else
sum += z;
}
pi = 4.0 * sum;
}