Advertisement
rotti321

Diferenta a doua fractii

Jan 11th, 2022
819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. /*Avem fractiile a/b si c/d.
  2. Afisati fractia diferenta (x/y = a/b-c/d) sub forma ireductibila
  3. Ex: 17/75 - 2/75 = 1/5
  4. Date de intrare a,b,c,d
  5. Date de iesire: x,y
  6. */
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. int main(){
  11.     int a,b,c,d;
  12.     int x,y;
  13.     cin >> a >>b>>c>>d;
  14.     x=a*d-c*b;
  15.     y=b*d;
  16.    
  17.     int A=x,B=y,r;
  18.     while(B!=0){
  19.         r=A%B;
  20.         A=B;
  21.         B=r;
  22.     }
  23.     cout << x/A << " " << y/A;
  24.    
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement