zoukankan      html  css  js  c++  java
  • 计算圆周率

    据说有个计算圆周率的外星人程序,如下:

    #include<cstdio>
    #include<cstdlib>
     int a=10000,b,c=8400,d,e,f[8401],g;
    int main()
    {
        
        for(;b-c;) f[b++]=a/5;
        for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)
        for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
        
        system("pause");
        return 0;
    }

    稍微整理:

    #include<cstdio>
    #include<cstdlib>
    int main()
    {
        int f[8401], a, b, c = sizeof(f) / sizeof(f[0]) - 1, d, e, g;
        for (a = 10000, b = e = 0; b != c; ) f[b++] = a / 5;
        for (; g = c * 2; c -= 14, printf("%.4d", e + d / a), e = d % a)
        for (d = 0, b = c; d += f[b] * a, f[b] = d % --g, --b; d *= b) d /= g--;
        
        system("pause");
        return 0;
    }

    看不出怎么计算的。。/_\

    计算圆周率的一个公式:

    pi

    代码验证:

    #include<cstdio>
    #include<cstdlib>
    int main()
    {
        double pi=2;
        for(int k=49;k>0;k--) 
            pi=pi*k/(2*k+1)+2;
        printf("pi=%.15lf...\n",pi);
        system("pause");
        return 0;
    }

    输出结果:pi = 3.141592653589793...

  • 相关阅读:
    Oracle 多表查询优化
    FZU 2150 Fire Game
    HDU 1058 Humble Numbers
    UVA 11624 Fire!
    POJ 1321 棋盘问题
    线性表的基本操作
    POJ 3414 Pots(广搜输出路径)
    HDU 1495 非常可乐
    POJ 1847 Tram
    POJ 3159 Candies(查分约束)
  • 原文地址:https://www.cnblogs.com/sooner/p/3028955.html
Copyright © 2011-2022 走看看