Write a program in c laungage that prints a table of the binary, octal and hexadecimal equivalents of the decimal numbers in the range1 through 256. Functions are not allowed and built-in functions for octa,binary and hexadecimal are also not allowed.
Below is the c solution with output screenshot
Code :
#include<stdio.h>
void convert (int num, int base)
{
int rem = num%base;
if(num==0)
return;
convert(num/base, base);
if(rem < 10)
printf("%d", rem);
else
printf("%c", rem-10+'A' );
}
int main()
{
printf("Decimal | Binary | Octal | Hexadecimal\n");
for(int i=1;i<=256;i++){
printf("%d | ", i);
convert(i,2);
printf(" | ");
convert(i,8);
printf(" | ");
convert(i,16);
printf("\n");
}
return 0;
}
Output :
...continued
Get Answers For Free
Most questions answered within 1 hours.