现在的位置: 首页 > 综合 > 正文

旧代码 – 高精度阶乘

2013年11月12日 ⁄ 综合 ⁄ 共 438字 ⁄ 字号 评论关闭
#include <stdio.h>

int    casenum,bit;
int    buf,res;
int    answer[9000];

int main()
{
    register int i,j;
    
    while (1 == scanf("%d", &casenum))
    {
        bit = answer[0] = 1;
        for (i=1; i<=casenum; ++i)
        {
            res = 0;
            for (j=0; j<bit; ++j)
            {
                buf = answer[j] * i + res;
                if (1 <= buf)
                {
                    answer[j] = buf % 100000;
                    res = buf / 100000;
                }   // End of if
            } // End of for
            while (res)
            {
                answer[bit++] = res % 100000;
                res /= 100000;
            } // End of while
        } // End of for
        
        printf("%d", answer[bit-1]);
        for (i=bit-2; i>=0; --i)
        {
            printf("%05d", answer[i]);
        }
        printf("\n");
    }
    return 0;
}

抱歉!评论已关闭.