{ ============== } { KSP 15. rocnik 1122: Binar Copyright (c) Jan Mojzis } { ============== } { Zadanie: } { Napiste program, kt. nacita kladne cislo n a vypise nasledujuci riadok: } { ,,dvojkovy zapis n"(2) = ,,desiatkovy zapis n" (10) } { PRIKLAD: Pre n = 10 vypise: 1010(2) = 10(10). } { OBMEDZENIE: V celom programe mozete pouzit iba procedury bez parametrov a } { jedinu jednoduchu globalnu premennu. } { ---------------------------------------------------------------------------} { Rekurzia. Vsimnite si ako testujeme parnost: } { if 1 and c = 0 je parna vetva, lebo } { 10 = 1010 and 0001 = 0 (0 x 1) a } { 11 = 1011 and 1 = 0001. } { Najrychlejsi test parnosti. } { } { Author: (c) 2007 Jan Mojzis } { Date : 06.07.2008 http://www.trsek.com } program binar; var c : integer; procedure vypis; forward; procedure nacitaj; begin writeln('daj cislo... rychlo nemam cas!'); readln(c); write('Cislo v desiatkovej ', c, '(10) = '); write('cislo v bin.: '); if c = 0 then write('0(2)') else if c = 1 then write('1(2)') else if c < 0 then write('---(2) zaporne cisla sa nehraju!') else if c > 0 then begin vypis; write('(2)'); end; end; procedure vypis; begin { if (c mod 2 = 0) and (c > 1)then begin } if (1 and c = 0) and (c > 1) then begin { PARNE BINARNE OPERACIE } c:=c div 2; vypis; write('0'); c:=c*2; end else if (1 and c = 1) then begin {and (c > 1) then begin} { NEPARNE } dec(c); c:=c div 2; vypis; write('1'); c:=c*2; inc(c); end; { if c and $4000 > 0 then write (1); < Ine mozne } { if c and $2000 > 0 then write(1) riesenie } { else if n > $2000 then write(0); v } { c:=c*2; } { end } { else if 1 and c = 1 then NEPARNE } { dec(c); } { c:=c mod 2; } {end; } end; begin nacitaj; readln; end.