There is such a program:
var n,c:integer; begin readln(n); while (n div 2 > 0) do begin c:=n mod 2; n:=n div 2; write(c,' '); end; write(1); end. I need to withdraw backwards. But better without using arrays.
There is such a program:
var n,c:integer; begin readln(n); while (n div 2 > 0) do begin c:=n mod 2; n:=n div 2; write(c,' '); end; write(1); end. I need to withdraw backwards. But better without using arrays.
Convert to binary representation is much easier:
for с := 31 downto 0 do Write((n shr с) and 1); If you want to trim the extra zeros on the left, you can, for example:
l := 0; repeat l := l + 1; if (n shr l) = 0 then Break; until l = 32; for c := l - 1 downto 0 do Write((n shr c) and 1); to and downto can behave differently. - Pavel Mayorovadd c to Your line and output the Line after the cycle:
var s:string; s = c + s; Source: https://ru.stackoverflow.com/questions/541172/
All Articles