注册 登录
编程论坛 新人交流区

[原创]大数的阶乘算法

xmzjerry 发布于 2007-10-22 18:13, 2581 次点击
*/ --------------------------------------------------------------------------------------
*/ 出自: 编程中国 https://www.bc-cn.net
*/ 作者: xmzjerry E-mail:xmzjerry@163.com
*/ 时间: 2007-10-22 编程论坛首发
*/ 声明: 尊重作者劳动,转载请保留本段文字
*/ --------------------------------------------------------------------------------------


#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;
}

5 回复
#2
火炫龙2007-10-24 20:15
为什么 无法执行程序呢?
#3
大旺旺2007-10-24 20:28
怎么了,这个程序没有什么问题啊?~~~~
#4
chenym2007-10-24 21:52
我的也是没法执行啊!!不知道问题何在··
#5
liuhanke2007-10-25 18:44

程序没有问题
我用vc++2005 去掉第一个无用#include "stdafx.h"
即可运行

#6
jasonguo2007-10-30 16:26
1