Question

When program uses loop inside GCD to compute the answer how to modify it so it...

When program uses loop inside GCD to compute the answer how to modify it so it becomes a recursive function call inside of the GCD function?

Homework Answers

Answer #1

/*If you any query do comment in the comment section else like the solution*/

GCD using iterative approach

int gcd(int A,int B)
        {
            int temp;
            while(B>0)
            {
                temp=B;
                B=A%B;
                A=temp;
            }
            return A;
        }

Modify the above code as below to make it recursive

private static int gcd(int A, int B) {
                if(A == 0) return B;
                if(B == 0) return A;
            return gcd(B, A%B);
        }
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Printing the value in the function, modify your function so that it returns a value of...
Printing the value in the function, modify your function so that it returns a value of true or false. Do not print anything from inside function itself. Call your function and have the return result of the function (Boolean True or False). Do not create a string called "True" or "False". Do not create a string called "Equal" or "Not Equal" here. Actually return a boolean. Create a variable in your main code outside of the is_equal function store the...
(Use C++ language) Create a program, named threeTypesLoops.cpp, that does the following; 1. Uses a For...
(Use C++ language) Create a program, named threeTypesLoops.cpp, that does the following; 1. Uses a For Loop that asks for a number between 1 and 10; Will double the number each time through the loop and display the answer. Will run five times, so the number will have been doubled five times, and the answer displayed five times. After the loop, display a message saying 'It's done!'. 2. Uses a While Loop; Ask the user to input a friend's name....
solve in python 3.8 please The question is about Strings Modify your function so that it...
solve in python 3.8 please The question is about Strings Modify your function so that it can handle the following two situations: The string given as an argument has no characters. In this case, you should return the empty string. The string given as an argument has one character. In this case, you should return the one-character string given to you. Without any consideration for these cases, your function probably causes an error or returns the wrong result in the...
In the main(), below, write a program that prompts for (1) how many values to sum,...
In the main(), below, write a program that prompts for (1) how many values to sum, and then (2) uses a summing loop to prompt for and add up 5 numbers. #include <iostream> #include <iomanip> using namespace std; int main() {     < your answer goes here> return 0; }
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
In C++ Please, In the main(), below, write a program that prompts for (1) how many...
In C++ Please, In the main(), below, write a program that prompts for (1) how many values to sum, and then (2) uses a summing loop to prompt for and add up 5 numbers. #include <iostream> #include <iomanip> using namespace std; int main() { < your answer goes here> return 0; }
Create a flowgorithm program to calculate the Area of Circle first then do the Circumference of...
Create a flowgorithm program to calculate the Area of Circle first then do the Circumference of Circle. The user will have the ability to convert Area OR the Circumference. That means we need to add a decision structure to the program. Furthermore, they need to be able to do it as many times as they want. That means we need to add a main loop structure to the program. The user will also have the choice of whether to run...
Coffee Order Structure Assignment Write a program that uses a structure for a coffee order. A...
Coffee Order Structure Assignment Write a program that uses a structure for a coffee order. A coffee order consists of a double price, a string for flavor, and characters for cream (Y/N), sugar (Y/N), and coffee size (S/M/L). Your main() function will call an order function that will ask the user for the flavor, size and whether or not they want cream or sugar. Your main() function will then create a coffee order structure and assign all of the values...
In C programming, Thank you Write a program to compute the area of a circle. You...
In C programming, Thank you Write a program to compute the area of a circle. You have to write a complete “C” program that compiles and runs in Codeblocks. Program requirements: 1. Declare the variables needed: radius (r) and area (yourLastName). 2. Calculate and print the area of each circle. 3. The program MUST prompt the user for a new radius (r) over and over until the user types -1. 5. Use the type double for all decimal numbers. 6....
When composing the models of two functions, how are the input/output units of the inside and...
When composing the models of two functions, how are the input/output units of the inside and outside functions related? When working with products of models, how are the input/output units of the models related? Explain, using examples, how the units help interpret the meaning of the derivative in context. Please, need the answer ASAP.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT