Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure readnum(var inp: longint);
- begin
- read(inp); //read num
- end;
- function pwr(in1,in2:longint):longint;
- var res,i:longint;
- begin
- res:=1; //firstly result eq 1
- for i:=1 to in2 do //repeat n2 times
- res:=res*in1; //res eq itself multiplie on in1
- pwr:=res; //assign to the function result res value
- end;
- procedure writePwrs(inp: longint); //
- var
- i: longint;
- begin
- if inp <= 1 then //if input value eq or less then inputted value then
- write('0') //write '0'
- else //else
- for i := inp downto 1 do //iterate all nums from inputted to 1
- if i mod 2 = 0 then //if present num is even then
- write(' ', pwr(2, i)); //write space and 2^i
- end;
- var
- inp: longint;
- begin
- readnum(inp); //read num
- writePwrs(inp); //write powers of 2
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement