Hey i\'m writing a program that converts decimal numbers into any base unit from binary to hexadecimal (2,3,4,....,15,16). This is what I have so far, running any number fro
#include
void main(void) {
char base_digits[16] =
{'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
char converted_number[32];
long int number_to_convert;
int base, index=0;
printf("Enter number and desired base: ");
scanf("%ld %i", &number_to_convert, &base);
while (number_to_convert != 0)
{
converted_number[index] = base_digits[number_to_convert % base];
number_to_convert = number_to_convert / base;
++index;
}
--index;
printf("\n\nConverted Number = ");
for( ; index>=0; index--)
{
printf("%c", converted_number[index]);
}
printf("\n");
}