怎样用c语言编写求PI的近似值?

[复制链接]
查看11 | 回复3 | 2012-3-27 10:11:12 | 显示全部楼层 |阅读模式
#include#includemain(){double t,pi;long int n,s;t=1.0;n=1;s=1;pi=0.0;while (fabs(t)>=1e-6){
pi=pi+t;
n=n+2;
s=-s;
t=(float)(s)/(float)(n); }pi=pi*4;printf("
pi=%lf\n",pi); }...
回复

使用道具 举报

千问 | 2012-3-27 10:11:12 | 显示全部楼层
float pi=355/113; 或者引入库函数 math.h#include math.hmain(){//直接可以用PI了}...
回复

使用道具 举报

千问 | 2012-3-27 10:11:12 | 显示全部楼层
ddxzcxz...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行