小编Pat*_*tya的帖子

为什么要使用递归来求一个数的阶乘?

为什么我们不能直接使用它呢main
为什么要有递归呢?

#include<stdio.h>
int factorial(int n);
int main()
{
    int n;
    printf("Enter an positive integer: ");
    scanf("%d",&n);
    printf("Factorial of %d = %ld", n, factorial(n));
    return 0;
}

int factorial(int n)
{
    if(n!=1)
    return n*factorial(n-1);
}
Run Code Online (Sandbox Code Playgroud)

c codeblocks

2
推荐指数
1
解决办法
259
查看次数

标签 统计

c ×1

codeblocks ×1