Đọc từ tệp BINARY.INP số nguyên dương n (0
Đọc từ tệp BINARY.INP số nguyên dương n (0
By Sadie
By Sadie
*Dùng đệ quy.
uses crt;
var f:text; n:longint;
b:array[1..10000]of longint;
procedure print;
var i:longint;
begin
for i:=1 to n do write(f,b[i]);
writeln(f);
end;
function dequy(a:longint):longint;
var i:longint;
begin
if a=n+1 then print else
for i:=0 to 1 Do
begin
b[a]:=i;
dequy(a+1);
end;
end;
begin
clrscr;
assign(f,’BINARY.INP‘);reset(f);
readln(f,n);
close(f);
assign(f,’BINARY.OUT‘);rewrite(f);
dequy(1);
close(f);
end.
const
Inp = ‘BINARY.INP’;
Outp = ‘BINARY.OUT’;
var
a: array[1..10000] of byte;
n: word;
f: Text;
procedure Print;
var
i: word;
begin
for i := 1 to n do Write(f, a[i]);
WriteLn(f);
end;
procedure Try(i: word);
var
j: word;
begin
for j:=0 to 1 do
begin
a[i]:=j;
if i=n then Print
else Try(i+1);
end;
end;
begin
Assign(f, Inp); Reset(f);
ReadLn(f, n); Close(f);
Assign(f, Outp); Rewrite(f);
Try(1); Close(f);
end.