Question: C++ problem: Write a program that reduces a fraction to lowest terms. Two functions should be implemented. Function gcd should find and return the greatest
C++ problem: Write a program that reduces a fraction to lowest terms. Two functions should be implemented. Function gcd should find and return the greatest common denominator and be called as g = gcd(num,den);. Function reduce(num,den); should call gcd to provide the lowest terms. The lowest terms should be returned via reference in num and den.
Pseudo code for gcd is:
function gcd(a, b)
while b 0
t = b
b = a mod b
a = t
return a
Example Output:
This program takes a numerator and denominator and reduces to lowest terms
Enter the numerator
28 35
Enter the denominator
greatest common denominator is 7
your fraction reduced is 4/5
Try Again? (1 = yes, 0 = exit)
1
Enter the numerator
85
Enter the denominator
1210
greatest common denominator is 5
your fraction reduced is 17/242
Try Again? (1 = yes, 0 = exit)
1
Enter the numerator
289
Enter the denominator
5148
greatest common denominator is 1
your fraction reduced is 289/5148
Try Again? (1 = yes, 0 = exit)
1
Enter the numerator
306
Enter the denominator
697
greatest common denominator is 17
your fraction reduced is 18/41
Try Again? (1 = yes, 0 = exit)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
