Ask your own question, for FREE!
Computer Science 13 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
Countless7Echos: Ah trying out the whole T.V girl drawing :p (I love drawing eyes)
2 hours ago 7 Replies 5 Medals
kaelynw: starting to draw a hand
1 day ago 16 Replies 2 Medals
Twaylor: Rate it :D (Took 2 days)
2 days ago 7 Replies 0 Medals
XShawtyX: Art, Short Writing Assignment: Imagining Landscapes
3 hours ago 7 Replies 1 Medal
XShawtyX: Chemistry, Help ud83dude4fud83cudffe
3 days ago 13 Replies 1 Medal
kaelynw: tried a lil smt, the arm is off but i like the other stuff
3 days ago 27 Replies 3 Medals
kaelynw: art igg
3 days ago 14 Replies 1 Medal
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!