Using Recursion to raise a base to its exponent - C++

后端 未结 5 681
不知归路
不知归路 2020-12-22 10:42

I simply want to write some code that makes use of recursion of functions to raise a base to its power. I know that recursion is not the most right way to do things in C++,

5条回答
  •  太阳男子
    2020-12-22 11:18

    Your problem lies here

    if (exponent > 0)
        return 1;
    else if (exponent = 0)
    

    firstly, you've inverted the conditional (if the exponent is equal to zero, it should return), secondly, you are assigning and not comparing with the second if.

提交回复
热议问题