Program to compare two fractions | CPP program to find max between two Rational numbers ; Get max of the two fractions ; Declare nume1 and nume2 for get the value of first numerator and second numerator ; Compute ad - bc ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Fraction { int num , den ; } ; Fraction maxFraction ( Fraction first , Fraction sec ) { int a = first . num ; int b = first . den ; int c = sec . num ; int d = sec . den ; int Y = a * d - b * c ; return ( Y > 0 ) ? first : sec ; } int main ( ) { Fraction first = { 3 , 2 } ; Fraction sec = { 3 , 4 } ; Fraction res = maxFraction ( first , sec ) ; cout << res . num << " / " << res . den ; return 0 ; }