Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language is c++ and need to run it in code blocks. this whole is one program so please write according to it. more practice with

Language is c++ and need to run it in code blocks.

this whole is one program so please write according to it.

more practice with recursion

write recursive functions to do each of the following. Create a main() function to call each of these functions to make sure that they work correctly. Note, you will receive no credit for functions that do not solve the problem recursively.

1. Write a function called power that takes two positive integers and raises the first to the power of the second. For example, power(2,4) would return 16 and power(3,3) would return 27. Here is the function prototype: int power(int base, int exponent);

2. Write a function called gcd that takes two integers and returns the greatest common divisor of the two integers. HINT: It might help to google Euclid gcd algorithm. Here is the function prototype:

int gcd(int M, int N);

3. Write a function called sumBetween that takes two integers and finds the sum of all integers between them inclusive. For example, sumBetween(6,8) would return 21, sumBetween(-2,-4) would return -9, and sumBetween(5,5) would return 5. Here is the function prototype:

int sumBetween(int X, int Y);

4. Write a function called sumEvens that takes two integers and finds the sum of all even integers between them inclusive. For example, sumEvens(6,10) would return 24, sumEvens(-3,-5) would return -4, sumEvens(5,5) would return 0, and sumEvens(8,8) would return 8. Here is the function prototype:

int sumEvens(int X, int Y);

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_2

Step: 3

blur-text-image_3

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

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

9. Describe the characteristics of power.

Answered: 1 week ago