Write program that lets the user enter a fraction numerator and denominator as two integers,
then simplifies the fraction by dividing each integer by the greatest common divisor (GCD). The
GCD is computed using the Euclidean algorithm.
First you must develop the function
euclid(a, b) that returns the greatest common
divisor of integers a and b.
Then write a short main program to:
• Repeatedly ask the user for the numerator and denominator;
Example:
Enter the numerator> 63
Enter the denominator> 35
• Convert the input values to integers;
• Call the function;
• Divide the numerator and denominator by the GCD returned by the function call;
• Print the result showing the original fraction, the simplified fraction and the GCD.
Example:
63/35 = 9/5 (GCD=7)
The Euclidean algorithm [1] uses the remainder of an integer division to iteratively arrive at the
greatest common divisor of two integers, in other words, the largest integer that can exactly
divide variables A and B? Another way of describing this is that the remainder of A + GCD is
zero, and remainder of B+ GCD is zero.
1. Take any two integers A and B
2. Calculate the remainder R of the integer division A/B
3. If R is equal to 0, then the answer is B. Stop.
4. Adjust the values: A takes the value B, and B takes the value R
5. Repeat from step 2
English (India)