利用递归求某数的阶乘——C/C++

#include<stdio.h>

int getFactorial(int n)
{
    if(n==0)
        return 1;
    else 
        return n*getFactorial(n-1);
}

int main()
{
    int n,res;
    scanf("%d",&n);
    res = getFactorial(n);
    printf("%d",res);
    return 0;
}

 

posted @ 2019-03-26 14:45  蝉鸣的Summer  阅读(318)  评论(0编辑  收藏  举报