uses crt;
var a,b,c,d,tu,msc,ucln,i:integer;
begin
clrscr;
write('Nhap tu cua phan so thu 1:'); readln(a);
repeat
write('Nhap mau cua phan so thu 1:'); readln(b);
until b<>0;
write('Nhap tu cua phan so thu 2:'); readln(c);
repeat
write('Nhap mau cua phan so thu 2:'); readln(d);
until d<>0;
msc:=b*d;
tu:=a*d+b*c;
ucln:=1;
if msc<tu then
begin
for i:=1 to msc do
if (msc mod i=0) and (tu mod i=0) then
begin
if ucln<i then ucln:=i;
end;
end;
if msc=tu then ucln:=tu;
if msc>tu then
begin
for i:=1 to tu do
if (msc mod i=0) and (tu mod i=0) then
begin
if ucln<i then ucln:=i;
end;
end;
if (msc div ucln)=1 then writeln(a,'/',b,'+',c,'/',d,'=',tu div ucln)
else writeln(a,'/',b,'+',c,'/',d,'=',tu div ucln,'/',msc div ucln);
readln;
end.
program hieups; var a,b,c,d,msc: longint; function UCLN(a,b: longint): longint; var r: longint; begin r := a mod b; while r <> 0 do begin r := a mod b; a := b; b := r; end; UCLN := a; end; procedure Output; var t: longint; begin if (a mod msc = 0) then write(a div msc) else begin t := UCLN(a,msc); a := a div t; msc := msc div t; if msc < 0 then write(-a,'/',abs(msc)) else write(a,'/',msc); end; end; begin readln(a,b,c,d); msc := b * d; a := (a * d) - (c * b); Output; end.
program hieups;
var a,b,c,d,msc: longint;
function UCLN(a,b: longint): longint;
var r: longint;
begin
r := a mod b;
while r <> 0 do
begin
r := a mod b;
a := b;
b := r;
end;
UCLN := a;
end;
procedure Output;
var t: longint;
begin
if (a mod msc = 0) then
write(a div msc)
else
begin
t := UCLN(a,msc);
a := a div t;
msc := msc div t;
if msc < 0 then
write(-a,'/',abs(msc))
else
write(a,'/',msc);
end;
end;
begin
readln(a,b,c,d);
msc := b * d;
a := (a * d) - (c * b);
Output;
end.