1025:求PI*

来源:互联网 发布:无线ad hoc网络 编辑:程序博客网 时间:2024/05/21 06:15

1025:求PI*

Description


输入n (n<=8)计算PI

公式pi^2/6=1/1^2+1/2^2+.....+1/m^2

取恰当的m满足精度的


Input


精度n


Output


对应的值(未一位请四舍五入)


Sample Input


6


Sample Output


3.141593


#include<iostream>#include<math.h>#include<stdio.h>using namespace std;int main(){    int n,i;   while(cin>>n)  {    double pi=0,count=0;    for(i=1;i<=n*10000;i++)       {         count=count+1.0/(i*i);       }    pi=sqrt(count*6);    cout<<pi;  }    return 0; } 




原创粉丝点击