program ubah_desimal_binary;
uses wincrt;
const n=100;
type stack = record
elemen:array[1..n]of integer;
top:integer;
end;
function isiempty(s:stack):boolean;
begin
isiempty:=(s.top=0);
end;
function isifull(s:stack):boolean;
begin
isifull:=(s.top=n);
end;
procedure create_stack(var s:stack);
begin
s.top:=0;
end;
procedure push(var s:stack; a:integer);
begin
if not (isifull(s)) then
begin
s.top:=s.top+1;
s.elemen[s.top]:=a;
end
end;
procedure pop(var s:stack; var a:integer);
begin
if not (isiempty(s)) then
begin
a:=s.elemen[s.top];
s.top:=s.top-1;
end
end;
function convert(a:integer):integer;
var y,x:integer;
z,tmp:string;
s:stack;
begin
create_stack(s);
while a>0 do
begin
y:=a mod 2;
push(s,y);
a:=a div 2;
end;
tmp:='';
while not isiempty(s) do
begin
pop(s,a);
str(a,z);
tmp:=tmp+z;
end;
val(tmp,a,a);
convert:=a;
end;
var i,hasil:integer;
begin
write('Masukan nilai desimal = ');readln(i);
hasil:=convert(i);
writeln(hasil);
end.
No comments:
Post a Comment