1076: N的阶乘
时间限制: 10Sec
内存限制: 128MB
提交:287
解决:88
题目描述
输入
输出
输入可能包括多组数据,对于每一组输入数据,输出N的阶乘
样例输入
样例输出
提示
来源
#include <iostream>
using namespace std;
int main()
{
intresult[10000];
int n;
int i=0,j=0;
inthigh=-1;
int c=0;
while(cin>>n)
{
if(n==0)
{
cout<<1<<endl;
}
else
{
for(i=0;i<10000;i++)
{
result[i]=0;
}
i=0;
int tem = n;
while(tem)
{
result[i] =tem % 10;
high++;
tem = tem /10;
i++;
}
for(i =n-1;i>1 ;i--)
{
for(j=0;j<=high;j++)
{
result[j] =result[j] * i;
}
for(j=0;j<=high;j++)
{
result[j] += c;
c =result[j]/10;
result[j] %=10;
}
while(c)
{
high ++;
result[high] = c;
c =c/10;
}
c=0;
}
for(i = high;i>=0;i--)
{
cout<<result[i];
}
cout<<endl;
high =-1;
}
}
return0;
}