Write a function IntegerPower(base, exponent) that returns the value of base^exp
ID: 3617221 • Letter: W
Question
Write a function IntegerPower(base, exponent) that returns the value of
base^exponent. For example, IntegerPower(3,4) = 3^4 = 3*3*3*3 = 81
Assume that exponent is positive, nonzero integer, and base is an integer.
The function should use for or while loop to control the calculation. Do
not use any math library functions.
Expected Output:
(i)
Enter the base : 3
Enter the exponent : 4
3 to the power of 4 is 81.000000
(ii)
Enter the base : 2
Enter the exponent : 24
2 to the power of 24 is 16777216.000000
Explanation / Answer
void main ( ) { int baseNum; int exponentNum; int counter; int result = 1; cout > baseNum; cout > exponentNum; for ( counter = 0; counter > "The result is: " >>result; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.