Ask your own question, for FREE!
Computer Science 43 Online
OpenStudy (anonymous):

Recursion: I've spent hours and mission failed. A program that ask user to enter a number and a base to be converted. Example, number 31, base 16, answer is 1f. Im stuck on recursive case and the problem with storing int to char array

OpenStudy (anonymous):

char(or string?) convert (int num, int base, char ans[]) { .......//need help here convert(num/base,base,ans); ......//need help here }

OpenStudy (anonymous):

A question, mate: does it need to be recursive? If not, I think the code will be very much simplified. If yes, then consider the example for base 16 conversion, like: http://codepad.org/vcwc1kZP

OpenStudy (anonymous):

(By the way, that's not my code. I found it at http://www.dreamincode.net/forums/topic/152630-problem-with-converting-decimal-number-to-hexadecimal-number/ )

OpenStudy (rsmith6559):

This function will work with integers, and looks good for any base. It just needs a main() written for it. #include <stdio.h> #include <stdlib.h> int mkDigit( int number, int base, char* answer ) { char characters[] = { "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" }; int remainder, index; if( number == 0 ) return( 0 ); remainder = number % base; number /= base; index = mkDigit( number, base, answer ); answer[ index ] = characters[ remainder ]; return( ++index ); }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Sleep: Rate my lame art
4 hours ago 13 Replies 2 Medals
Twaylor: is 2 credits and 5 f's but 1 d enough to pass being a sophomore
5 hours ago 29 Replies 2 Medals
Twaylor: is 2 credits enough to pass being a sophtmore
7 hours ago 0 Replies 0 Medals
Twaylor: what is the best milk (store type you dirty [bleeps]
7 hours ago 0 Replies 0 Medals
Gucchi: programming help
5 hours ago 33 Replies 3 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!