📜  阶乘尾递归 - 无论代码示例

📅  最后修改于: 2022-03-11 14:57:30.489000             🧑  作者: Mango

代码示例1
nt factTR(unsigned int n, unsigned int a)
{
    if (n == 0)
    {
        return a;
    }
    else
    {
        return factTR(n - 1, n * a);
    }

}

int fact(unsigned int n);
{
    return factTR(n, 1);
}

int main(void)
{
    unsigned int a, n;

    printf("Enter a positive number : ");
    scanf("%u", &n);
    a = fact(n);

    printf("The factorial of %u is %u", n, a);

    return 0;
}