正文

大数的阶乘算法2007-12-14 23:49:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/chaotic/31430.html

分享到:

  读大学的时候很多语言课程都会布置这个做大数阶乘算法的作业,今天我就把他贴出来,以后大家都不用愁了。 #include "stdafx.h"#include "stdio.h"#include "iostream.h" int main(int argc, char* argv[]){    int carry,n,j;    int a[2000];    int digit=1;    int temp,i;    cout<<"please enter n:"<<endl;    cin>>n;    a[0]=1;    for(i=2; i<=n; i++)    {        for(carry=0,j=1; j<=digit; ++j)        {            temp=a[j-1]*i+carry;            a[j-1]=temp%10;            carry=temp/10;        }        while(carry)        {            //digit++;            a[++digit-1]=carry%10;            carry/=10;        }    }    cout<<"the result is:"<<endl;    for(int k=digit; k>=1; --k)        cout<<a[k-1];    cout<<endl;    return 0;}

阅读(1727) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册