Ask Question
29 July, 11:13

Write a recursive function power (base, exponent) that, when invoked returns base exponent For example, power (3, 4) = 3*3*3*3. Assume that exponent is an integer greater than or equal to 1.

+1
Answers (1)
  1. 29 July, 12:25
    0
    int power (int base, int exponent)

    {

    if (exponent==1) / /base case.

    return base;

    return base*power (base, exponent-1); //recursive call.

    }

    Explanation:

    The above written function is for calculating base^exponent using recursion. In calculating the power n of a number we have multiply that number with itself n times. So the recursion is calculating the base^exponent-1 and we are multiplying the last base by ourselves.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a recursive function power (base, exponent) that, when invoked returns base exponent For example, power (3, 4) = 3*3*3*3. Assume that ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers