您的位置:首页 > 编程语言

旧代码 - 高精度阶乘

2013-03-05 09:53 148 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: