[Functions]D. Liang 5.14 Computing series.c

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;
}
发布了131 篇原创文章 · 获赞 94 · 访问量 2938

猜你喜欢

转载自blog.csdn.net/qq_45645641/article/details/105169360