| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 611 人关注过本帖
标题:求圆周率,怎样输出前100位,或者N位.
只看楼主 加入收藏
忘了
Rank: 2
等 级:论坛游民
帖 子:16
专家分:55
注 册:2010-5-17
结帖率:100%
收藏
 问题点数:0 回复次数:1 
求圆周率,怎样输出前100位,或者N位.
就是那个1-1/3+1/5-1/7 ……,即使用双精度也只能输出没几位啊,那肯定要断开一位一位输出了,怎么做啊,头都大了,理了一点,懒得写下去了,高手给个答案
    void next(double a);
                         main()
                         {double a=1,b,c,d=-1,f,sum=1;
                         int e=1,h,i;
                         for(b=0;b<10;b++,e++)
                          {
                              f=sum*4;
                               h=f;

                              printf("sum1=%d\n",h);
                        {   a=a+2;  c=a;

                         c=(d)*(1/c);

                           d=(-1)*d ;
                           sum+=c;      }
                               i=4*sum  ;
                                  printf("sum2=%d\n",i);
                                  if(h==i)
                                 { printf("%d=%d,\n",h,i) ;
                                  a=a-4;   sum=0;  d=(-1)*d ; /*计算下一位*/
                                  {  f=sum*10;
                                      h=f;

                                    printf("sumNEXT1=%d\n",h);
                                   a=a+2;  c=a;

                         c=(d)*(1/c);

                           d=(-1)*d ;
                           sum+=c;      }    }

                              if(e%10000==0)
                             { e=1;
                               printf("yuan=%lf\n",4*sum); }
                          }
                             printf("yuan=%lf\n",4*sum);
                           getch();}
                           void next(double a)
                      {   double b,c,d=-1,f,sum=1;
                         int e=1,h,i,u;
                      if(h==i)
                      {  a=a-4;   sum=0;  d=(-1)*d ;
              a=a+2;  c=a;   c=(d)*(1/c);     d=(-1)*d ; sum+=c; i=sum1=sum*40; }

                      else
                    {a=a+2;  c=a; c=(d)*(1/c); d=(-1)*d ;  sum+=c; h=sum2=sum*40  }
                    if(h==i)
                    next(a);}
                        h=sum*10;                      }
搜索更多相关主题的帖子: 输出 圆周率 
2010-05-17 13:58
冥卫
Rank: 8Rank: 8
来 自:深山老林
等 级:蝙蝠侠
帖 子:280
专家分:772
注 册:2010-4-20
收藏
得分:0 
注意数据类型的取值范围
2010-05-17 14:58
快速回复:求圆周率,怎样输出前100位,或者N位.
数据加载中...
 
   



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

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