看看这题c++算π怎么算?4(1 - 1/3 + 1/5 - 1/7 + 1/9 - ... -1/(2n-1) + 1/(2n+1))

m(i)=4(1-1/3+1/5-1/7+1/9-...-1/(2n-1)+1/(2n+1))Writeafunctionthatreturnsm(n)withthefo... m(i) = 4(1 - 1/3 + 1/5 - 1/7 + 1/9 - ... -1/(2n-1) + 1/(2n+1))
Write a function that returns m(n) with the following function head.

double pi(int n)

提示
You should submit the implementation of the function but do not submit the main() function.
展开
 我来答
百度网友58b11544e
推荐于2016-12-02
知道答主
回答量:30
采纳率:0%
帮助的人:15.7万
展开全部
#include<stdio.h>
#include<math.h>
double pi(int n)
{
double sum = 1;
for(int i = 1;i <= n;i ++)
{
sum += 1.0/(2*n + 1) * (pow(-1,n));

}
return sum * 4;
}
int main()
{
printf("%f\n",pi(1));

return 0;
}
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式