Previous Exercise
Course Outline
For Exercise 3, let's practice some logic skills and implement a recursive function.
Problem:
Write a program that asks the user for two inputs - base and exponent. Define a recursive function power(int base, int exponent) that will compute for the result and display it on screen. For simplicity, assume that both the base and exponent are integers and the latter is non-negative.
Hint:
For any integer x,
x0 = 1
x1 = x
xn = x * xn-1
Previous Exercise
Course Outline
No comments:
Post a Comment