Ask Question

Complete the recursive function raisetopower (). ex: if userbase is 2 and userexponent is 4, then raisedvalue is assigned with 16 (i. e. 2^4). note: this example is for practicing recursion; a non-recursive function, or using the built-in function pow (), would be more common.

+1
Answers (1)
  1. 8 May, 14:36
    0
    Using the property that x^n is x*x^ (n-1) you can write a recursive function:

    double raisetopower (double x, int n)

    {

    if (n < = 0) {

    return 1.0;

    }

    return x*raisetopower (x, n - 1);

    }

    Note that this crude implementation does not deal with negative or fractional exponents. But it shows recursion.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Complete the recursive function raisetopower (). ex: if userbase is 2 and userexponent is 4, then raisedvalue is assigned with 16 (i. e. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers