Description
The value of π can be approximately estimated using the following formula:
Input
A positive integer n (1 <= n <= 10000)
Output
The series computing by n
(The precision of series should be fixed to 5)
Sample Input
10
Sample Output
3.23232
// Date:2020/3/28
// Author:xiezhg5
#include <stdio.h>
int main(void)
{
int i;
int n,t=1;
double sum=0,a;
scanf("%d",&n);
for(i=0;i<=n;i++)
{
a=2.0*i+1.0;
sum=sum+t*(1.0/a);
t=-t;
}
printf("%.5lf\n",4.0*sum);
return 0;
}