用c語言編程計算π的值
辟霞17814563860咨詢: 誰能幫我做一個C語言的編程,關(guān)于圓周率π的值的 -
鏡湖區(qū)螺紋回復(fù):
______ 程序如下:#include<stdio.h>#include<conio.h>#include<math.h>int main(){ int n,i; float s,pi; i=2; printf("請輸入截斷項數(shù):"); scanf("%d",&n); s=1; if(n<2) { s=1; } else { for(i=2;i<=n;i++) s=s+1/(i*i); } pi=sqrt(6*s); printf("圓周率π的近似值為%f",pi); getch(); }
辟霞17814563860咨詢: c語言 用公式計算π
鏡湖區(qū)螺紋回復(fù):
______ m沒有初始化導(dǎo)致; #include<stdio.h> #include <math.h> void main() { float PI,m=1,a=1,b;//m初始化才有效 int n=1; while(m>1e-5) { a=a*(2*n)/(2*n-1)*(2*n)/(2*n+1); b=a*(2*n+2)/(2*n+1)*(2*n+2)/(2*n+3); m=2*b-2*a; n++; } PI=2*a; printf("PI=%f\n",PI); getch(); }
辟霞17814563860咨詢: c語言 用公式計算π -
鏡湖區(qū)螺紋回復(fù):
______ m沒有初始化導(dǎo)致;#include#include void main() { float PI,m=1,a=1,b;//m初始化才有效 int n=1; while(m>1e-5) { a=a*(2*n)/(2*n-1)*(2*n)/(2*n+1); b=a*(2*n+2)/(2*n+1)*(2*n+2)/(2*n+3); m=2*b-2*a; n++; } PI=2*a; printf("PI=%f\n",PI); getch(); }
辟霞17814563860咨詢: 怎樣用C語言/C++求算π以后的值啊? -
鏡湖區(qū)螺紋回復(fù):
______ π/4=1-1/3+1/5-1/7+1/9.....以此類推 你可以用一個循環(huán)語句來提高精度 或者編一個高精度之類的 程序?qū)崿F(xiàn)就隨意了~~
辟霞17814563860咨詢: c語言怎么用函數(shù)實現(xiàn)求π/2的值 -
鏡湖區(qū)螺紋回復(fù):
______ 公式 代入 x=1 得 下面是C語言遞歸實現(xiàn): #include<stdio.h> #include<math.h> void main() { float fuc(int n); float s,pi,pi2; for(int i=1;i<10000;i++) {s=1.0/(2*i-1); if(s<1e-6) break;} pi=fuc(i)*4; //求出π的值 pi2= pi * 2; printf ("pi2=%10.6f\n",pi2...
辟霞17814563860咨詢: 在c語言中,利用迭代求π的值,迭代式為: π/2=1+1!/3+2!/(3*5)+3!/(3*5*7)+…+( -
鏡湖區(qū)螺紋回復(fù):
______ 先把2i改成2*i試試……
辟霞17814563860咨詢: 用c語言計算圓周率 -
鏡湖區(qū)螺紋回復(fù):
______ 不知道這樣行不行 R確定(或是任取) 正8邊形的面積 - 正4邊形面積 正16邊形的面積 - 正8邊形面積 ............到要求精確到小數(shù)點幾位的面積S(相對準(zhǔn)確的圓面積----即正N邊形面積) 然后π=S/R/R
辟霞17814563860咨詢: c語言編程 3 - 4. 求π的近似值 有加分 -
鏡湖區(qū)螺紋回復(fù):
______ main() {double pai,e,temp,i; int fuhao; printf("輸入:\n"); scanf("%lf",&e); pai=0.0; i=0.0; fuhao=1; if (e<=0) printf("error!\n"); else { temp=1.0/(2*i+1); while(temp>=e) {pai+=fuhao*temp; i++; temp=1.0/(2*i+1); fuhao=-fuhao; } print(".5lf\n",pai); } }
辟霞17814563860咨詢: 用C語言編個程序,求π(派)
鏡湖區(qū)螺紋回復(fù):
______ #include <stdlib.h> #include <time.h> #include <math.h> #include <stdio.h> main () { int x,y; long i,m=0; double d,r=32767; float pi,n=5000000; srand (time(0)); for(i=0;i<n;i++) {x=rand(); y=rand(); d=sqrt(x*x+y*y); if (d<r) {m=m+1;...
辟霞17814563860咨詢: 急啊!請編寫一個C語言程序,根據(jù)以下公式求π的值(要求滿足精度0.0005,即某項小于0.0005時停止迭代) -
鏡湖區(qū)螺紋回復(fù):
______ #include double fun(double eps) { double s=1.0;float t=1,pi=0,n=1.0; while((fabs(s))>=eps) { pi+=s; t=n/(2*n+1); s*=t;n++; } pi=pi*2; return pi; } main() { double x; printf("Input eps:"); scanf("%lf",&x); printf("\neps=%lf, PI=%lf\n",x,fun(x)); }