Answer:
Following are the code to this question:
RaiseToPower(baseVal, exponentVal-1);//calling method RaiseToPower and in second parameter we subtract value
resultVal = baseVal * RaiseToPower(baseVal, exponentVal-1);//defining resultVal variable that calculate baseVal and method value
Step-by-step explanation:
In the above-given code inside the "RaiseToPower" method is defined that accepts two parameters, which are "baseVal and exponentVal" and inside the method, an integer variable "resultVal" is defined, that holds a value that is 0.
- In the next step, if the conditional statement is used, in if the block it checks the "exponentVal" variable value that is equal to 0, if it is true it assigns value 1 in "resultVal" otherwise it will go to else block in this block, the "resultVal" variable holds "baseVal" variable value and call the "RaiseToPower" method, and multiply the baseVal and method and store its value in resultVal and return the value.
- Inside the main method, two integer variable userBase, userExponent is defined that holds a value and calls the above method and prints its return value.
please find the attachment of the code file and its output.