zoukankan      html  css  js  c++  java
  • (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

    } 

    作者:cpoint
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    KMP算法
    IEEE754 32位浮点数表示范围
    银行家算法
    字符串类
    栈类
    稀疏数组类
    队列类
    多维数组类
    单向链表类
    哈希表类
  • 原文地址:https://www.cnblogs.com/cpoint/p/2015284.html
Copyright © 2011-2022 走看看