0 bình luận về “viết chương trình tìm UCLN của x,y (pascal)”
program Tim_UCLN; uses crt; var a, b, x, y, UC:integer; begin clrscr; writeln(‘Nhap 2 so can tim: ‘); Readln(a,b); a:=x; b:=y; while x<>y do begin if x>y then x:=x-y else y:=y-x; end; UC:=x; {Hoặc y cũng được} writeln(‘UCLN cua 2 so ‘,a, ‘va ‘, b,’la :’, UC); readln; end.
program Tim_UCLN;
uses crt;
var a, b, x, y, UC:integer;
begin
clrscr;
writeln(‘Nhap 2 so can tim: ‘);
Readln(a,b);
a:=x;
b:=y;
while x<>y do
begin
if x>y then x:=x-y
else y:=y-x;
end;
UC:=x; {Hoặc y cũng được}
writeln(‘UCLN cua 2 so ‘,a, ‘va ‘, b,’la :’, UC);
readln;
end.
uses crt;
var a, b, x, y, sd, UC: integer;
begin
clrscr;
write (‘nhap a: ‘); readln (a);
write (‘nhap b: ‘); readln (b);
x:=a;
y:=b;
while (b<>0) do
begin
sd:=a mod b;
a:=b;
b:=sd;
end;
writeln;
UC:=a;
writeln (‘ucln cua ‘,x,’ va ‘,y,’ la: ‘,UC);
readln;
end.