用C语言编写一个求圆周率的程序

如题所述

#include<stdio.h>
main()
{ float s,r,PI;
clrscr();
printf("input周长 s");
scanf("%f",&s);
printf("input半径 r");
scanf("%f",&r);
PI=s/(2*r);
pringf("周长=%f,半径=%f\n圆周率PI=%f",s,r,PI);

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-20
#include<stdio.h>
main()
{
int i,j=0;
double pa=0;
for(i=1;i<400;i=i+2)
{
if(j==0)
{pa=pa+1.0/i;<br/> j=1;<br/> }
else
{pa=pa-1.0/i;<br/> j=0;<br/> }
}
pa=pa*4;
printf("%f\n",pa);
}

求圆周率的近似值 纯C语言本回答被网友采纳
第2个回答  2017-10-31
楼上的那个 i<400这个400改成更大的数精确度会高点,还有printf后改成%.50lf\n可以算到小数点后50位,这个50也是可以改的。外加一句,一般电脑很难算到50位
第3个回答  2019-12-22
#include<stdio.h>
long a=10000,b,c=2800,d,e,f[2801],g;
main()
{
for(;b-c;)
f[b++]=a/5;
for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)
for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
scanf("%s");
return 0;
}
第4个回答  2020-11-02
#include<bits/stdc++.h>
#include<windows.h>
#include<cstdio>
using namespace std;
void HideCursor(){
HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle,&CursorInfo);
CursorInfo.bVisible=false;
SetConsoleCursorInfo(handle,&CursorInfo);
}
int main(){
double x=1.0,Pi=1.0,t=1.0,p=1.0;
int i=0;
HideCursor();
while(p>1e-10){
i++;
x+=2.0;
p=1.0/x;
if(i%2!=0)
Pi-=p;
else Pi+=p;
t+=1.0;
printf("Pi:%.150lf\n",Pi*4.0);
system("cls");
}
printf("%.40lf\n",Pi*4.0);
return 0;
}

相关了解……

你可能感兴趣的内容

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