Question
Asked Dec 9, 2019
4 views
12. Consider the recursive function (from class) int gcd( int a, int b)
int gcd( int a, int b){
if (b > a) return gcd(b,a);
if ( b == 0 ) return a;
return gcd( b, a% b);
}
How many invocation (calls) of the gcd() function will be made by the call gcd(72, 30) ?
help_outline

Image Transcriptionclose

12. Consider the recursive function (from class) int gcd( int a, int b) int gcd( int a, int b){ if (b > a) return gcd(b,a); if ( b == 0 ) return a; return gcd( b, a% b); } How many invocation (calls) of the gcd() function will be made by the call gcd(72, 30) ?

fullscreen
check_circle

Expert Answer

Step 1

Recursive function: A recursive function is a function that during its execution calls itself.

Code:

#include <iostream>

using namespace std;

//gcd function to calculate the gcd of two numbers

int gcd(int a, int b) {

  if (b > a)

    return gcd(b, a);

  if (b == 0)

    return a;

  return gcd(b, a % b);

}

//main method

int main() {

  //calling gcd function to find gcd of 72 and 30   

  cout << gcd(72, 30);

  return 0;

}

 

Step 2

Output:

Output of above program is g...

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: What is the SQL command to change the BEST_SELLER column in the MYSTERY table to reject nulls (table...

A: Below is the SQL command to create the table MYSTERY.In the given SQL statement NOT NULL constraint ...

question_answer

Q: Why are jumping statements in c? Explain with help of examples?

A: Definition of jump statement in C language –Jumps statements are used to disrupt the program’s norma...

question_answer

Q: what is the cpu time when the number of instructions executed by the program is 500, cycles per inst...

A: CPU time (or CPU Execution time) is the time between the start and the finishing(end) of execution o...

question_answer

Q: Python 3.7.4: I have project named “MOREPioneers.py “.  I need to take a text file named Pioneers.tx...

A: Program Instructions:  ⦁ Create a .txt file first and insert all the names of influencer of computer...

question_answer

Q: Write some MYSQL code to select three different sets of data and display them on the screen. Also, d...

A: Creating Table and Inserting then values into it-The Create Table statement is used to create a tabl...

question_answer

Q: Write a statement that calls the function AddToStock with parameters computerInfo and addQty. Assign...

A: The updated C++ code and the missing statement are given below:

question_answer

Q: Microsoft Excel 2016 has many new and improved functions. What do you think is the most beneficial f...

A: Beneficial functions in MS-Excel 2016:3D data Maps:In the 2013 version, the 3D data map was actually...

question_answer

Q: Simplify the following Boolean function and expression, using four-variable maps  a) cF(w,x,y,z) = Σ...

A: Since you have posted multiple parts and have not specified which part needs to be answered. So, we ...

question_answer

Q: Write a program in python with no imports that the owner of Chica Chic could use to store data about...

A: open is used to open file in write mode “w”.while(True) is used to repetitive input.input() function...