小编may*_*raj的帖子

为什么我的阶乘程序可以运行,但我几乎相同的 pow 程序却不起作用?

这是我的阶乘程序——它正在执行并给出正确的结果:

#include <stdio.h>

int main()
{
    int n;

    printf("enter the no=");
    scanf("%d", &n);
    fun(n);
    printf("%d\n", fun(n));

    return 0;
}

int fun(int n)
{
    if(n == 0)
        return 1;
    else
        return fun(n - 1) * n;
}
Run Code Online (Sandbox Code Playgroud)

这是我计算一个数的幂的程序——这给出了 0 而不是正确的结果,但几乎相同:

#include <stdio.h>

int main()
{
    int m, n;

    printf("enter the no=");
    scanf("%d%d", &m, &n);
    pow(m, n);
    printf("%d\n", pow(m, n));

    return 0;
}
int pow(int m, int n)
{
    if(n == 0)
        return 1;
    else
        return pow(m, n - 1) * m; …
Run Code Online (Sandbox Code Playgroud)

c gcc compiler-optimization pow

5
推荐指数
1
解决办法
106
查看次数

标签 统计

c ×1

compiler-optimization ×1

gcc ×1

pow ×1