Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago