用C语言编程:π*π/6=1/1*1+1/2*2+1/3*3+。。。+1/n*n,求出π的值

要求:(1)以变量 pi表示π,并将其自定义为单精度类型,变量n定义为整型;
(2)计算当 n的值分别为20,50,100,200时的π值;
(3)输出π值以及总的项数n,输出格式为“n=值,pi=值”。
哥们 能好好写一下吗

程序如下:

//Author : Zhaing&bo
//Date : 2010-11-22
//Version: 0.1
#include <stdio.h>
#include <math.h>

int main(void) {

char c;
int i, n = 0;
float pi, pi6 = 0.0;

printf("Press y | Y to start.\n");
while (c=getchar(), c=='y' || c=='Y') {
printf("Please input a integer:");
scanf("%d", &n);

for (i=1,pi6=0.0; i<=n; i++) {
pi6 += 1.0/(i*i);
}

pi = (float)sqrt(pi6*6);
printf("n=%d, pi=%f\n", n, pi);
fflush(stdin);
printf("Press y | Y to again:");
}

printf("Press any key to continue...");
fflush(stdin);
getchar();
return 0;
}
// 至此结束

认真回答,呈请采纳
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-11-21
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
main()
{ int n,i;
float pi,sum=0,m=1.0;
scanf(本回答被提问者和网友采纳
第2个回答  2010-11-22
百度跟以前变了
不知道怎么回事
代码只显示一部分啊 好奇怪

相关了解……

你可能感兴趣的内容

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