Advertisement
STANAANDREY

pbinfo fr

Nov 17th, 2019
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. typedef struct
  5. {
  6.     int a, b;
  7. } FRAC;
  8.  
  9. int main()
  10. {
  11.     FRAC f1, f2;
  12.     cin >> f1.a >> f1.b;
  13.     cin >> f2.a >> f2.b;
  14.  
  15.     int cmmdc, a = f1.a, b = f1.b, r;
  16.     while(b != 0)
  17.     {
  18.         r = a % b;
  19.         a = b;
  20.         b = r;
  21.     }
  22.     cmmdc = a;
  23.  
  24.     f1.a /= cmmdc;
  25.     f1.b /= cmmdc;
  26.  
  27.     a = f2.a;
  28.     b = f2.b;
  29.     while(b != 0)
  30.     {
  31.         r = a % b;
  32.         a = b;
  33.         b = r;
  34.     }
  35.     cmmdc = a;
  36.  
  37.     f2.a /= cmmdc;
  38.     f2.b /= cmmdc;
  39.  
  40.     if (float(f1.a/f1.b) > float(f2.a/f2.b))
  41.         cout << f1.a << ' ' << f1.b;
  42.     else
  43.         cout << f2.a << ' ' << f2.b;
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement