hey im trying to create a program to convert dec to hex , but this only lets me print either integers or chars , but not both , how do i fix that ?
int convertHex(int num)
{
quotient=(num / 16);
remainder=(num % 16);
if (remainder <= 9 && quotient >= 1)
{
b[j++]=remainder;
count++;
convertHex(quotient);
}
else if(remainder > 9 && quotient >= 1)
{
b[j++]=((remainder-10)+'A');
count++;
convertHex(quotient);
}
else if(quotient <= 0)
{
(remainder <= 9 ) ? (b[j++]= remainder) : (b[j++]=((remainder-10)+'A'));
count++;
//reverse(b,count);
for( j = 0 ; j < count ; j++)
printf("%d",b[j]);
printf("\n");
b[bits];
count = 0;
for (j = 0; j < count; ++j)
{
b[j] = 0;
}
return b[0];
}
}
ive also written another function but it displays the number in reverse ?
int convertHex(int num)
{
quotient=(num / 16);
remainder=(num % 16);
if (remainder <= 9 && quotient >= 1)
{
printf("%d",remainder);
convertHex(quotient);
}
else if(remainder > 9 && quotient >= 1)
{
printf("%c",((remainder-10)+'A'));
convertHex(quotient);
}
else if(quotient <= 0)
{
(remainder <= 9 ) ? printf("%d",remainder): printf("%c",((remainder-10)+'A'));
printf("\n");
return 0;
}
}
can anyone fix either one ?..please..i need to submit it before monday!
p.s - were not allowed to use %x :(