0

Hi, I have given a task to write a code about approximate of pi. this is what I wrote from the other example.

the task is to :

(pi^2)/16 = ((-1)^k)/k+1 (1+1/3+1/5+...+1/(2k+1))

Write a program which computes and prints an approximation of pi using a finite number of terms from the above formula. The number of terms must be input from the keyboard (via scanf ). The program must also print an approximation error: the difference between the approximation and the value of pi stored in the macro constant M_PI, defined in <math.h>.

```
`//*pi^2 / 16 = (-1)^N / N(N+1) (1 + (1/3)) + (1/5) + ... + ( 1/((2*N)+1)))*\\
#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
int main()
{ int N, i;
double sum=0;
printf("Enter number of terms: ");
scanf("%d",&N);
for (i = 1; i <= N; i++)
{
sum += 1.0/i/i; /* try 1.0/(i*i), N=100000 */
}
printf("pi = %g\n\n", sqrt(6*sum));}`
```

I'm not sure is this right or not, but i think this is wrong. so can someone give me some advice?

Thanks for the help