[ Outline ] · Standard · Linear+

> Pretvaranje decimalnog zapisa u binarni, Pascal

Laza_91
post May 27 2007, 06:38 PM
Post #1





Group: Članovi
Joined: 20-May 06
Member No.: 63



E jel moze neko da mi napise funkciju za prevodjenje broja iz dekadnog u binarni brojni sistem...
Do sutra...Ako je moguce sad.gif
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
 
Reply to this topicStart new topicStart Poll
Replies
username
post Feb 17 2008, 07:07 PM
Post #2





Group: Članovi
Joined: 29-September 07
Member No.: 684
Status: Bivši učenik MGa



CODE

program MinBC;
var n,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,t:integer;
begin
readln(n);
t:=1;
while not n div t <10 do
t:=t*10;
a0:=0;
a1:=0;
a2:=0;
a3:=0;
a4:=0;
a5:=0;
a6:=0;
a7:=0;
a8:=0;
a9:=0;
repeat
case n mod 10 of
0: a0:=a0+1;
1: a1:=a1+1;
2: a2:=a2+1;
3: a3:=a3+1;
4: a4:=a4+1;
5: a5:=a5+1;
6: a6:=a6+1;
7: a7:=a7+1;
8: a8:=a8+1;
9: a9:=a9+1
end;
n:=n div 10;
until n=0;
while a9>0 do
begin
n:=n+9*t;
a9:=a9-1;
t:=t div 10;
end;
while a8>0 do
begin
n:=n+8*t;
a8:=a8-1;
t:=t div 10;
end;
while a7>0 do
begin
n:=n+7*t;
a7:=a7-1;
t:=t div 10;
end;
while a6>0 do
begin
n:=n+6*t;
a6:=a6-1;
t:=t div 10;
end;
while a5>0 do
begin
n:=n+5*t;
a5:=a5-1;
t:=t div 10;
end;
while a4>0 do
begin
n:=n+4*t;
a4:=a4-1;
t:=t div 10;
end;
while a3>0 do
begin
n:=n+3*t;
a3:=a3-1;
t:=t div 10;
end;
while a2>0 do
begin
n:=n+2*t;
a2:=a2-1;
t:=t div 10;
end;
while a1>0 do
begin
n:=n+1*t;
a1:=a1-1;
t:=t div 10;
end;
writeln(n);
readln;
end.


This post has been edited by username: Feb 17 2008, 07:19 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post



Reply to this topicTopic OptionsStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: