text: Find max of two Rational numbers | CPP program to find max between two Rational numbers ; Get lcm of two number 's ; Get max rational number ; Find the LCM of first -> denominator and sec -> denominator ; Declare nume1 and nume2 for get the value of first numerator and second numerator ; Driver Code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; struct Rational { int nume , deno ; } ; int lcm ( int a , int b ) { return ( a * b ) / ( __gcd ( a , b ) ) ; } Rational maxRational ( Rational first , Rational sec ) { int k = lcm ( first . deno , sec . deno ) ; int nume1 = first . nume ; int nume2 = sec . nume ; nume1 *= k / ( first . deno ) ; nume2 *= k / ( sec . deno ) ; return ( nume2 < nume1 ) ? first : sec ; } int main ( ) { Rational first = { 3 , 2 } ; Rational sec = { 3 , 4 } ; Rational res = maxRational ( first , sec ) ; cout << res . nume << " / " << res . deno ; return 0 ; }