tính UCLN của a và b
program uoc_chung;
uses crt;
var a,b: integer;
begin
writeln('nhap a='); readln(a);
writeln('nhap b='); readln(b);
while a>b do then a:=a-b
else b:=b-a;
if a=b then write ('uoc chung lon nhat la',a)
readln;
end.
BCNN tương tự
Program ucln_bcnn;
Uses crt;
Var x,y,uc,t,tamx,tamy:integer;
Begin
Clrscr;
Write('Nhap so nguyen duong x : '); readln(x);
Write('Nhap so nguyen duong y : '); readln(y);
tamx:=x;
tamy:=y;
t:=y mod x;
while t<>0 do
begin
t:=x mod y;
x:=y;
y:=t;
end;
uc:=x;
Writeln('- Ucln(' , tamx , ',' , tamy , ') la : ',uc );
Writeln('- Bcnn(' , tamx , ',' , tamy , ') la : ',(tamx*tamy) div uc );
Readln;
End.