#include<fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
struct rational {int nr, nu;};
void citire(rational &r)
{
fin>>r.nr>>r.nu;
}
void afisare(rational r)
{
fout<<r.nr<<"/"<<r.nu<<" ";
}
int cmmdc(int a, int b)
{
if (a % b == 0) return b;
else return cmmdc(b, a % b);
}
void simplific(rational &r)
{
int c = cmmdc(abs(r.nr), abs(r.nu));
r.nu = r.nu / c;
r.nr = r.nr / c;
if(r.nr*r.nu<0)
{
r.nu=abs(r.nu);
r.nr=-abs(r.nr);
}
else
{
r.nu=abs(r.nu);
r.nr=abs(r.nr);
}
}
rational adunare(rational x, rational y)
{
int a = x.nr * y.nu + x.nu * y.nr;
int b = x.nu * y.nu;
rational r;
r.nr=a; r.nu=b;
simplific(r);
return r;
}
rational scadere(rational x, rational y)
{
int a = x.nr * y.nu - x.nu * y.nr;
int b = x.nu * y.nu;
rational r;
r.nr=a; r.nu=b;
simplific(r);
return r;
}
rational inmultire(rational x, rational y)
{
int a = x.nr * y.nr;
int b = x.nu * y.nu;
rational r;
r.nr=a; r.nu=b;
simplific(r);
return r;
}
rational impartire(rational x, rational y)
{
int a = x.nr * y.nu;
int b = x.nu * y.nr;
rational r;
r.nr=a; r.nu=b;
simplific(r);
return r;
}
int maimic (rational x, rational y)
{
int a = x.nr * y.nu;
int b = x.nu * y.nr;
return a < b;
}
int maimare (rational x, rational y)
{
int a = x.nr * y.nu;
int b = x.nu * y.nr;
return a > b;
}
int egal(rational x, rational y)
{
int a = x.nr * y.nu;
int b = x.nu * y.nr;
return a == b;
}
int main()
{
rational a,b,s;
citire(a);
citire(b);
s=adunare(a,b);
afisare(s);
s=scadere(a,b);
afisare(s);
s=inmultire(a,b);
afisare(s);
s=impartire(a,b);
afisare(s);
if(maimic(a,b)) fout<<"maimic\n";
else fout<<"nu e mai mic\n";
if(maimare(a,b)) fout<<"maimare\n";
else fout<<"nu e mai mare\n";
if(egal(a,b)) fout<<"egale\n";
else fout<<"diferite\n";
fin.close();
fout.close();
return 0;
}
|