要求:(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;
}
// 至此结束
认真回答,呈请采纳
//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(本回答被提问者和网友采纳
#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
百度跟以前变了
不知道怎么回事
代码只显示一部分啊 好奇怪
不知道怎么回事
代码只显示一部分啊 好奇怪