标题:请大家看一看我的求圆周率的程序错在哪?
只看楼主
心若止水
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2008-4-9
得分:0 
好象不大对啊,f[b++]=a/5;即为  f[b++]=10000/5=2000;2000是一个常量不变的啊。
2008-04-22 10:22
海铭
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-4-21
得分:0 
#include <stdio.h>/*根据公式Pi=4(1-1/3+1/5-1/7+...)求圆周率*/
int main(void)    /*要求直到某项绝对值小于1e-6为止*/
{
    float t=1,p=1,pi;
    int n=1;
    int s=1;
    while(t>1e-6)
    {
        t=1.0/(2*n+1);
        s=-s;
        p+=s*t;
        n++;
     }
     pi=4*p;
     printf("%f",pi);
     return 0;
}
2008-04-22 12:36
jinxilee
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2008-4-6
得分:0 
t>=-5时,为什么无论t怎么改变,结果都是3.141416呢
#include<stdio.h>/*根据公式Pi=4(1-1/3+1/5-1/7+...)求圆周率*/
#include<math.h>
int main(void)    /*要求直到某项绝对值小于1e-6为止*/
{
    float t=1.0,p=0,P;
    int n=1;
    int s=-1;
    while(t>1e-10)
    {
    t=1.0/(2*n-1);
        s=-s;
    p=p+s*t;
        n++;
     }
     P=4.0*p;
     printf("%9f",P);
}

2008-04-22 13:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-209776-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.205263 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved