(HDOJ 1042)N!

N!
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
3
 

Sample Output
6
 

Author
JGShining(极光炫影)
 

 AC code:

#include<stdio.h>
int main()
{
    
int a[10000];
    
int i,j,c,m,n;
    
while(scanf("%d",&n)!=EOF){
    a[
0]=1;
    m
=0
    
for(i=1;i<=n;i++)
    { 
        c
=0
        
for(j=0;j<=m;j++)
        { 
        a[j]
=a[j]*i+c; 
        c
=a[j]/10000
        a[j]
=a[j]%10000
        } 
    
if(c>0) {m++;a[m]=c;} 
    } 
    printf(
"%d",a[m]); 
    
for(i=m-1;i>=0;i--) printf("%4.4d",a[i]);
    printf(
"\n");
    }
    
return 0

} 

posted @ 2011-04-13 21:07  cpoint  阅读(601)  评论(0编辑  收藏  举报
浏览次数:travelocity promotion codes