Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int Cmmdc(int x, int y)
- {
- int r;
- while(y!=0)
- {
- r=x%y;
- x=y;
- y=r;
- }
- return x;
- }
- int Cmmmc(int x,int y)
- {
- int t;
- t=(x*y)/Cmmdc(x,y);
- return t;
- }
- int main()
- {
- int a,b,c, d,n=0,m=0,a1,b1,c1,d1;
- cin>>a>>b>>c>>d;
- a1=a;
- b1=b;
- c1=c;
- d1=d;
- while(b!=d)
- {
- a=a*Cmmmc(b,d)/b;
- c=c*Cmmmc(b,d)/d;
- b*=Cmmmc(b,d)/b;
- d*=Cmmmc(b,d)/d;
- }
- cout<<a+c<<" "<<b<<"\n"; /// trebuie sa reduci la o forma ireductila si fractia (a+c)/b
- n=a1*c1;
- m=b1*d1;
- while(Cmmdc(n,m)!=1)
- {
- n=n/Cmmdc(n,m);
- m=m/Cmmdc(n,m);
- }
- cout<<n<<" "<<m;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement