Question: Write a C + + program that reads two Integers from the standard input and compute their GCD ( Greatest Common Divisor ) . The

Write a C++ program that reads two Integers from the standard input and compute their GCD
(Greatest Common Divisor). The GCD among two numbers is the greatest Integer that is the
greatest common factor number that divides them, exactly. Any correct implementation is fine.
One simple implementation is the Euclid recursive implementation that computes the GCD of
two Integers a and b with a recursive function gcd(a,b) that delivers a, if b is equal to zero, or
delivers the gcd(b,c) where c is the remainder of the Integer division of a by b(c=amodb).
For example:
the GCD between 12 and 8 is computed as:
@,gcd(12,8)=gcd(8,12mod8)=gcd(8,4)
@,gcd(8,4)=gcd(4,8mod4)=gcd(4,0)
@,gcd(4,0)=4
the GCD between 48 and 18 is computed as:
gcd(48,18)=gcd(18,48mod18)=gcd(18,12)
gcd(18,12)=gcd(12,18mod12)=gcd(12,6)
gcd(12,6)=gcd(6,12mod6)=gcd(6,0)
gcd(6,0)=6
Run the code and and print out the execution for this three sets of numbers as test case:
513 and 39
1812 and 210
1533 and 133
Deliverable
The code including the main function calling the three test cases;
The output of the program generated for the three test cases.
Write a C + + program that reads two Integers

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 Programming Questions!