Home › Forums › C Programming › convert decimal to binary › Re: Re: convert decimal to binary
August 8, 2009 at 7:07 pm
#3600
GWILouisaxwzkla
Participant
could try this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <br /> #include <br /> <br /> void main()<br /> {<br /> <br /> int i;<br /> cout << "Enter a number to convert ";<br /> cin >> i;<br /> int binaryArray [ 20 ] ; //whatever<br /> int j = 0;<br /> while ( i )<br /> {<br /> binaryArray [ j ++ ] = i % 2 ;<br /> i /= 2;<br /> }<br /> <br /> cout << endl << "Binary Version: " ;<br /> while ( j -- > 0 )<br /> cout << binaryArray [ j ];<br /> cout << endl;<br /> }<br /> |