• 阶乘算法简单实现


    long int fac1(int n)
    {
     static long int f=1;
     f*=n;
     return f;
    }

    long int fac2(int n)
    {
     long int f=1;
     if(n==0|n==1)
     {
      f=1;
     }
     else
     {
      f=n*fac2(n-1);
     }

    return f;
    }

    void main()
    {
     int i;
     for(i=1;i<=8;i++)
     {
      printf("fac1[%d!]=%ld /n",i,fac1(i));
     }
     
     printf("fac2[8!]=%ld /n",fac2(8));
    }

  • 相关阅读:
    day66
    1
    day65
    BeautifulSoup
    day60
    day59
    day49
    day48
    [S5PV210] PWM
    [S5PV210] Clock
  • 原文地址:https://www.cnblogs.com/LoongEmbedded/p/5298800.html
Copyright © 2020-2023  润新知