Doi co so - ngan xep

Màu nền
Font chữ
Font size
Chiều cao dòng

program doicoso;
uses dos;
const stacklimit=50;
type kieu_ptu=integer;
day_nganxep=array [1..stacklimit] of kieu_ptu;
kieu_nganxep=record
top:0..stacklimit;
phantu:day_nganxep;
end;
var so,sodu:integer;
stack:kieu_nganxep;
traloi:char;


procedure thietlap(var stack:kieu_nganxep);
begin stack.top:=0 end;


function isempty(stack:kieu_nganxep):boolean;
begin isempty:=(stack.top=0) end;


procedure top(var stack:kieu_nganxep;var item:kieu_ptu);
begin if isempty(stack) then halt
else with stack do
begin item:=phantu[top];
top:=top-1;
end;
end;


procedure them(var stack:kieu_nganxep;item:kieu_ptu);
begin if stack.top=stacklimit then halt
else with stack do
begin top:=top+1;
phantu[top]:=item;
end;
end;


begin
repeat
write('nhap so can doi,so=');readln(so);
thietlap(stack);
while so<>0 do
begin sodu:=so mod 2;
them(stack,sodu);
so:=so div 2;
end;
writeln('bieu dien co so 2');
while not isempty(stack) do
begin top(stack,sodu);
write(sodu:1);
end;
readln;
write('co lam tiep khong?(y/n)');readln(traloi);
until not(upcase(traloi)='y')
end.

Bạn đang đọc truyện trên: Truyen2U.Pro