написать задачу перевода из 10 с.с. в 2 с.с. двумя способами: 1) функции 2) процедуры
Answers & Comments
HRAshton
Function toBin(dec: integer): string; var buf: integer; str: string; begin buf := dec; repeat str := concat(IntToStr(buf mod 2), str); buf := buf div 2; until (buf = 0); toBin := str; end;
procedure toBin(dec: integer; var bin: string); var buf: integer; begin buf := dec; repeat bin := concat(IntToStr(buf mod 2), bin); buf := buf div 2; until (buf = 0); end;
var s: string;
begin writeln(toBin(10)); toBin(10, s); writeln(s); end.
Answers & Comments
var
buf: integer;
str: string;
begin
buf := dec;
repeat
str := concat(IntToStr(buf mod 2), str);
buf := buf div 2;
until (buf = 0);
toBin := str;
end;
procedure toBin(dec: integer; var bin: string);
var
buf: integer;
begin
buf := dec;
repeat
bin := concat(IntToStr(buf mod 2), bin);
buf := buf div 2;
until (buf = 0);
end;
var
s: string;
begin
writeln(toBin(10));
toBin(10, s);
writeln(s);
end.