給定一個 n 值,請計算出 n! 的結果
輸入說明 :
輸入一個整數 n
輸出說明 :
輸出 n! 結果,結果不大於 2^63
範例輸入 :
0
1
5
範例輸出 :
1
1
120
程式碼 :
#include <stdio.h>
int main()
{
int i,n,max=1,temp;
long long arr[21]={1,1};
while(scanf("%d",&n)==1)
{
if(n > max)
{
temp = n + 1;
for(i=max+1;i<temp;i++)
arr[i] = arr[i-1] * i;
}
printf("%lld\n",arr[n]);
}
return 0;
}
http://zerojudge.tw/ShowProblem?problemid=a032
沒有留言:
張貼留言