CHAR;PROCEDURE NHAP; BEGIN WRITELN('NHAP SO THAP PHAN N

Bài 2:

var st,st2:string;

p,i,n,j,t:integer;

ch,ch1:char;

procedure nhap;

begin

writeln('nhap so thap phan n:');

readln(n);

end;

procedure doinp(n:integer);

var st1,stt:string;t,d:integer;

begin

st1:='';

repeat

t:=n div 2;

d:=n mod 2;

n:=t;

str(d,stt);

st1:=st1+stt;

until t=0;

for i:=length(st1) downto 1 do

write(st1[i]:3);

writeln;

end;

function hammu(n:integer):integer;

var p:integer;

begin

if n=0 then hammu:=1

else

p:=1;

for i:=1 to n do

begin

p:=P*2;

end;

hammu:=p;

end;

procedure doitp(st:string;var t:integer);

var so,k,i:integer;

begin

t:=0;

for i:=1 to length(st) do

val(st[i],k,so);

t:=t+k*hammu(length(st)-i);

end;

BEGIN

repeat

writeln(' moi ban chon chuc nang');

readln(ch1);

case ch1 of

'n': begin

nhap;

writeln('so thap phan', n ,' doi thanh day nhi phan:');

doinp(n);

end;

't': begin

writeln(' moi ban nhap day so nhi phan can doi');

readln(st2);

doitp(st2,t);

writeln(t);

writeln('doi nua khong?');

readln(ch);

until ch in['k','K'];

END.