Question: Lab 2 - Recursive Algorithms For this lab you will implement 3 different recursive algorithms. Create a single file called lab2.cpp which includes main )

 Lab 2 - Recursive Algorithms For this lab you will implement
3 different recursive algorithms. Create a single file called lab2.cpp which includes

Lab 2 - Recursive Algorithms For this lab you will implement 3 different recursive algorithms. Create a single file called lab2.cpp which includes main ) and all the functions required to implement the 3 recursive algorithms Problem 1 Recursive Exponentiation Write a recursive function power (base, exponent) that, when invoked, returns baseexponent For example, 34 would be power (3,4) would return 81. Assume the exponent is an integer greater than or equal too Your base case is base-1 Your recursion step will use the relationship baseespanent base baseesponene 1 Use main) to call power) 3 times and show the following output to the console: power (10,0)-1 power (2,101024 power (8,532768 Problem 2-Sum the Sequence Write a recursive function sum (n) which returns the sum of the integers from n through 0. Assume n is an integer greater than or equal to 0. For example, sum (4) calculates 4 3 2 1 0 and returns 10. sum (0) returns O Use main(to call sum) 3 times and show the following output to the console: sum (0)-0 sum (5)15 sum (10) -55 Problem 3-Sum the Digits Write a recursive function sumTheDigits (n) which returns the sum of the digits in integer n. Assume n is an integer greater than or equal to 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!