1177:计算N!
Description
你的好友小王最近学了一个新的运算法则-----阶乘,但他很懒,不想一步一步计算,早知道你是一个程序员高手,所以他想让你来帮他编一个程序,能马上得到N的阶乘。
Input
输入包含若干行数据,每行都有一个整数N(0<=N<=500)。
Output
与输入对应输出N的阶乘。
Sanple Input
2
4
Sample Output
2
24
Source
Icpc1st@ahstu
#include<iostream>
using namespace std;
int main()
{
int N,i,j;
while(cin>>N)
{
int a[17000]={0};
a[0]=1;
int temp,count=0;
for(i=2;i<=N;i++)
{
for(j=0;j<17000;j++)
{
temp=a[j]*i+count;
count=temp/10;
a[j]=temp%10;
}
}
for(i=16999;i>=0;i--)
{
if(a[i])
break;
}
for(int j=i;j>=0;j--)
cout<<a[j];
cout<<endl;
}
return 0;
}