Advertisement
STANAANDREY

21/1/2020

Jan 21st, 2020
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. void cmmdc(unsigned a, unsigned b, unsigned& dc)
  5. {
  6.     while (a != b)
  7.         if (a > b)
  8.         a -= b;
  9.     else
  10.         b -= a;
  11.     dc = a;
  12. }
  13.  
  14. void simplif(unsigned& x, unsigned& y)
  15. {
  16.     unsigned z;
  17.     cmmdc(x, y, z);
  18.     x /= z;
  19.     y /= z;
  20. }
  21.  
  22. int main()
  23. {
  24.     ifstream f("FR.IN");
  25.     ofstream g("FR.OUT");
  26.  
  27.     unsigned x, y;
  28.     while (f >> x >> y)
  29.     {
  30.         simplif(x, y);
  31.         g << x << ' ' << y << endl;
  32.     }
  33.     g.close();
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement