N!
N!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 55283 Accepted Submission(s): 15718
Problem Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
Input
One N in one line, process to the end of file.
Output
For each N, output N! in one line.
Sample Input
1
2
3
Sample Output
1
2
6
Author
JGShining(极光炫影)
Recommend
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main() 4 { 5 int N,Len,i,j,sign,Num; 6 int sum[10086]={0}; 7 while(scanf("%d",&N)!=EOF) /*输入N,输出N的阶乘*/ 8 { 9 Len=1; 10 sum[0]=1; 11 for(i=1;i<=N;i++) 12 { 13 for(j=0,sign=0;j<Len;j++) 14 { 15 Num=sum[j]*i+sign; 16 if(Num>=10000) 17 { 18 sign=Num/10000; 19 sum[j]=Num%10000; 20 } 21 else 22 { 23 sum[j]=Num; 24 sign=0; 25 } 26 if(j==Len-1&&sign) 27 { 28 Len++; 29 } 30 } 31 } 32 for(j=Len-1;j>=0;j--) 33 { 34 if(j!=Len-1) 35 printf("%04d",sum[j]); 36 else 37 printf("%d",sum[j]); 38 sum[j]=0; 39 } 40 putchar(10); 41 } 42 return 0; 43 }
转载请附上原帖地址:http://www.cnblogs.com/LWF5201314614/articles/4018064.html
转载请备注:
**************************************
* 作者: Wurq
* 博客: https://www.cnblogs.com/Wurq/
* Gitee: https://gitee.com/wurq
**************************************
**************************************
* 作者: Wurq
* 博客: https://www.cnblogs.com/Wurq/
* Gitee: https://gitee.com/wurq
**************************************

浙公网安备 33010602011771号