Reference no: EM132360821
Question :
Your assignment is to write a program that has two methods that computes xn using recursion and iteration. Remember xn is just x multiplied by itself n times. If n is 0 the result is defined to be 1, if n is one, the result is x, if n is two, the result is x times x, etc. The main program will solicit two numbers (x and n) from the user and call your x n method to compute
xn
X can be any decimal number, while n must be a non-negative integer. If a negative value is input for n, the program must display an error message and request input again until a legal value is input. When the method finally computes the value, it will return it to the main program which will display a message giving the original input numbers and the results of the power from the two functions (they had better be the same). It will then ask the user if he wants to determine x n for another pair of numbers.
Note that one method must use recursion to compute the value of xn, that is, the method calls itself until the value is computed. You can see a couple examples of recursion programs by looking at chapter 13 in your textbook. The other method must use iteration (a loop) to compute the value of xn.
As always make certain to have your name, the assignment number, and a brief description of theprogram in comments at the top of the program and have comments within the program.