zoukankan      html  css  js  c++  java
  • N的阶乘

    N的阶乘 

    Problem Description

    计算一个正整数的阶乘,数据范围[1,1000]

    Input

    每行一个整数N

    Output

    每行一个整数,表示N的阶乘

    Sample Input

    2
    5

    Sample Output

    2
    120
     1 #include<stdio.h>
     2 int main()
     3 {
     4     void fun(int n);
     5     int i,n,str[1000];
     6     while(scanf("%d",&n)!=EOF)
     7     fun(n);
     8       return 0;
     9 }
    10 void fun(int n)
    11 { int str[10000],i;
    12  str[0]=1;
    13  for(i=1;i<10000;i++)
    14  str[i]=NULL;
    15     int e=0,a=0,j,k=n;
    16     for(i=1;i<=n;i++)
    17     {for(j=0;j<=k;j++)
    18     {
    19         e=str[j]*i+a;
    20         a=e/10;
    21         str[j]=e%10;
    22     }
    23     k++;
    24     }
    25     while(1)
    26     {
    27         if(str[k]==0)k--;
    28         else break;
    29     }
    30     for(i=k;i>=0;i--)
    31     printf("%d",str[i]);
    32     printf("
    ");
    33 }
    View Code
  • 相关阅读:
    NGINX-HTTPS
    README
    SSH
    Ubuntu
    Python复利
    Python全双工聊天
    Python半双工聊天
    Python网络编程
    使用Python PIL库中的Image.thumbnail函数裁剪图片
    Python模块 os.walk
  • 原文地址:https://www.cnblogs.com/gznb/p/11213731.html
Copyright © 2011-2022 走看看