Câu 1:
uses crt;
var m,n,ucln,i:integer;
begin
clrscr;
write('Nhap m='); readln(m);
write('Nhap n='); readln(n);
ucln:=1;
if m<n then
begin
for i:=1 to m do
if (m mod i=0) and (n mod i=0) then
begin
if ucln<i then ucln:=i;
end;
end
else begin
for i:=1 to n do
if (m mod i=0) and (n mod i=0) then
begin
if ucln<i then ucln:=i;
end;
end;
writeln(ucln);
readln;
end.
Câu 2:
uses crt;
var m,n,bcnn,i:integer;
begin
clrscr;
write('Nhap m='); readln(m);
write('Nhap n='); readln(n);
bcnn:=m*n;
for i:=m*n-1 downto 1 do
if (i mod m=0) and (i mod n=0) then
begin
if bcnn>i then bcnn:=i;
end;
writeln(bcnn);
readln;
end.
BCNN:
program boichung;
var m,n: word;
procedure Input;
begin
readln(m,n);
end;
function BC(m,n: word): word;
var i: word;
begin
for i := 1 to n * m do
if (i mod n = 0) and (i mod m = 0) then
write(i,' ');
end;
begin
Input;
BC(m,n);
end.
UCLN:
program UCLN;
var m,n,r,i: longint;
begin
readln(n,m);
n := abs(n);
m := abs(m);
if (n = 0) then
begin
i := 1;
write(m);
end
else
if (m = 0) then
begin
i := 1;
write(n);
end;
r := n mod m;
while r <> 0 do
begin
r := n mod m;
n:= m;
m:= r;
end;
if (i = 0) then
write(n);
readln
end.