Advertisement
tanasaradu

Untitled

Oct 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int Cmmdc(int x, int y)
  5. {
  6. int r;
  7. while(y!=0)
  8. {
  9. r=x%y;
  10. x=y;
  11. y=r;
  12. }
  13. return x;
  14. }
  15. int Cmmmc(int x,int y)
  16. {
  17. int t;
  18. t=(x*y)/Cmmdc(x,y);
  19. return t;
  20. }
  21. int main()
  22. {
  23. int a,b,c, d,n=0,m=0,a1,b1,c1,d1;
  24. cin>>a>>b>>c>>d;
  25. a1=a;
  26. b1=b;
  27. c1=c;
  28. d1=d;
  29. while(b!=d)
  30. {
  31. a=a*Cmmmc(b,d)/b;
  32. c=c*Cmmmc(b,d)/d;
  33. b*=Cmmmc(b,d)/b;
  34. d*=Cmmmc(b,d)/d;
  35. }
  36. cout<<a+c<<" "<<b<<"\n"; /// trebuie sa reduci la o forma ireductila si fractia (a+c)/b
  37. n=a1*c1;
  38. m=b1*d1;
  39. while(Cmmdc(n,m)!=1)
  40. {
  41. n=n/Cmmdc(n,m);
  42. m=m/Cmmdc(n,m);
  43. }
  44. cout<<n<<" "<<m;
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement