COS1512 ASSIGNMENT 4 SOLUTIONS 2021 SEMESTER 1 AND 2
Question 1.
(a) Answer:
int number, int power
explanation: Declaring the input parameters
(b) Answer:
Line 10:
power == 0
explanation: when power becomes 0 will stop the recursion
Line 11:
1
explanation: for multiplication, we have to send back 1, so it can power it with 1
(c) Why do we need a base case in a recursive function?
Answer:
Because we have to stop recursive function, without base case recursive function will call itself infinitely.
Question 1.
(a) Answer:
int number, int power
explanation: Declaring the input parameters
(b) Answer:
Line 10:
power == 0
explanation: when power becomes 0 will stop the recursion
Line 11:
1
explanation: for multiplication, we have to send back 1, so it can power it with 1
(c) Why do we need a base case in a recursive function?
Answer:
Because we have to stop recursive function, without base case recursive function will call itself infinitely.