HDU 1042 N!

来源:互联网 发布:java 高斯模糊处理 编辑:程序博客网 时间:2024/04/29 22:16
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
123
Sample Output
126

#include<stdio.h>#include<string.h>int main(){    int n,i,j,temp,s;    int num[20000];    while(scanf("%d",&n)!=EOF)    {        memset(num,0,sizeof(num));        num[0]=1;        for(i=2;i<=n;i++)        {            int temp=0;            for(j=0;j<20000;j+=1)            {                s=num[j]*i+temp;                num[j]=s%1000;                temp=s/1000;            }        }        for(i=20000-1;i>-1;i--)if(num[i])break;        printf("%d",num[i]);        for(j=i-1;j>-1;j--)printf("%.3d",num[j]);        printf("\n");    }    return 0;}

 



原创粉丝点击