Home › Forums › C Programming › function › Reply To: function
September 2, 2008 at 1:26 pm
#3431
Humayan
Participant
binary conversion:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <iostream.h><br /> void main()<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 /> |
hex conversion:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <iostream.h><br /> void printHex ( int i );<br /> void main()<br /> {<br /> cout << "Enter a character: " ;<br /> char ch;<br /> cin >> ch;<br /> cout << endl << "Here is hex form of ASCII: " << endl;<br /> printHex ( ( int ) ch );<br /> cout << endl;<br /> <br /> <br /> <br /> }<br /> void printHex ( int i )<br /> {<br /> char base16 [ 17 ] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };<br /> <br /> if ( i == 0 )<br /> return;<br /> else<br /> {<br /> printHex ( i / 16 );<br /> cout << base16 [ i % 16 ];<br /> }<br /> } |
Is the merge sort on an array??