c语言编程6分之π²=1+2*2分之1+3*3分之1+…+n*n分之1

如题所述

#include <stdio.h>
#include <math.h>
void main(){
int i;
double pi=0;
for(i=1;1.0/(i*i)>=1e-6;i++)
pi+=1.0/(i*i);
printf("PI=%f",sqrt(pi*6));
}

从计算结果看,这个公式只能精确到小数点后第二位,这个计算公式的精度不是太高。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-01-09
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double sn=0,x=1,n=pow(10,-6);
while((1/(x*x))>n)
{
sn=sn+1/(x*x);
x=x+1;
}
cout<<sn<<endl;
return 0;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网