Đang tải... (xem toàn văn)
[r]
(1)Thuật toán tìm UCLN Bài toán: Tìm ƯCLN hai số tự nhiên a b
Gi¶i Program UCLN;
Uses CRT;
Var a, b, r, temp: byte; Begin
Clrscr;
Write('Moi ban nhap hai so a, b: ');readln(a,b); if (a = 0) and (b = 0) then
Begin
Write(' Moi ban nhap lai'); Exit;
End;
if (a = 0) then Begin
Write(' UCLN lµ ',b); Exit;
End;
if (b = 0) then Begin
Write(' UCLN lµ ',b); Exit;
End;
if (a<b) then Begin
temp:=a; a:= b; b:=temp; end;
r: = a mod b; While r <> Begin
a:= b; b:=r;
r: = a mod b; end;
Write(' UCLN = ',b); Readln;