Question
In c++, Write code to complete RaiseToPower(). Sample output if userBase is 4 and userExponent is 2 is shown below. Note: This example is for
In c++, Write code to complete RaiseToPower(). Sample output if userBase is 4 and userExponent is 2 is shown below. Note: This example is for practicing recursion; a non-recursive function, or using the built-in function pow(), would be more common.
4^2 = 16
#include
int RaiseToPower(int baseVal, int exponentVal){ int resultVal = 0;
if (exponentVal == 0) { resultVal = 1; } else { resultVal = baseVal * /* Your solution goes here */; }
return resultVal; }
int main() { int userBase = 0; int userExponent = 0;
userBase = 4; userExponent = 2; cout << userBase << "^" << userExponent << " = " << RaiseToPower(userBase, userExponent) << endl;
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started