hdoj1042

来源:互联网 发布:进销存 知乎 编辑:程序博客网 时间:2024/05/23 00:08

N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33698    Accepted Submission(s): 9380


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
 

Author
JGShining(极光炫影)
#include<stdio.h>#include<string.h>int number[100001];int main(void) {    int n;    while (scanf("%d", &n) != EOF) {        memset(number, 0, sizeof (number));        number[0] = 1;        int digit=0;//最高位        for (int i = 2; i <= n; i++) {            int c = 0;            for (int j = 0; j <=digit; j++) {                int s = number[j] * i + c;                number[j] = s % 10;                c = s / 10;            }            while(c){//进位                number[++digit]=c%10;                c/=10;                            }        }         for(int i=digit;i>=0;i--)            printf("%d",number[i]);        printf("\n");            }    return 0;}