I just need a help regarding this problem:

a user is asked to enter two fractions, and the program should print the following

-maximum
-sum
-product

Output should be in proper fractional from and should be in lowest terms. The program must be able to identify if the numbers entered for numerator or denominator are not integers and output “not valid”. This is also the case if the number 0 is entered denominator

I had the program fragments but I'm messed up with placing the fragments in their proper position.
I used n1, d1, n2, d2 to represent the four integers.
The function for the greatest common divisor is:

``````int gcd(int m, intn) {
if(n == 0) return m;
return gcd(n, m%n);
}``````

---regarding this, should I use void in this part.

sum is as follows:

``````n = n1 * d2 + n2 * d1;
d = d1 * d2;
int gcd = gcd(n,d)
n /= gcd;
d /= gcd``````

now n and d are in lowest terms which you can output

product is

``````n = n1*n2;
d = d1*d2;``````

again call gcd function here

for maximum you would do the following

``if(n1*d2 > n2 * d1) // n1/d1 is larger``

I just had the fragments but I need the whole code because I'm not pretty sure where will I place this and that.

2
Contributors
1