∑情华大学出版社 TSINGHUA UNIVERSITY PRESS 运行结果: 例54求p的近似值 #include stdio. h> pi=3.141594 #includemath. h> void main( I int s, float n, t, pi t=1;pi=0;n=1.0;s=1 while(fabs(t)>le-6 lpi=pitt: n=n+2, s=-s; t=s/n pi=pika printf(" pi=10. 6f \n", pi)例5.4 求pi的近似值 #include <stdio.h> #include<math.h> void main() { int s;float n,t,pi; t=1;pi=0;n=1.0;s=1; while(fabs(t)>1e-6) {pi=pi+t;n=n+2;s=-s;t=s/n;} pi=pi*4; printf(″pi=%10.6f\n″,pi); } = 100 n 1 n 运行结果: pi= 3.141594