zoukankan      html  css  js  c++  java
  • HDU 1042 大数阶乘

    B - 2
    Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    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


    代码:

    #include<stdio.h>
    #include<string.h>
    #define N 11000

    void pp(int a[],int num)
    {
    int i;
    for(i = 0;i < N;i++)
    a[i] = a[i] * num;

    for(i = 0;i < N;i++)
    {
    a[i+1] += a[i] / 10000;
    a[i] = a[i] % 10000;
    }
    }
    void put(int a[])
    {
    int i=N-1;

    while(!a[i])
    i--;
    printf("%d",a[i]);

    for(i--;i>=0;i--)
    printf("%04d",a[i]);

    }
    int main()
    {
    int a[N];
    int n,i;
    while(scanf("%d",&n) != EOF)
    {
    memset(a,0,sizeof(a));
    a[0]=1;
    for(i=1;i<=n;i++)
    {
    pp(a,i);
    }

    put(a);
    printf(" ");
    }
    return 0;
    }

  • 相关阅读:
    标准输入输出流
    打印流
    数据输入输出流
    对象操作流
    随机流
    内存输出流
    序列流
    转换流示例代码
    字符流的示例代码
    字符流
  • 原文地址:https://www.cnblogs.com/dll6/p/5777145.html
Copyright © 2011-2022 走看看