ProAnswers.org

Write a C program to convert decimal number to hexadecimal number?

#include

#include 

#include 

void main() 

{ 

Int x, y=30, z; 

clrscr(); 

printf(“Enter the number:”); 

scanf(“%d”, &x); 

printf(“

conversion of decimal to hexadecimal number
”);

for(;;) 

{ 

if(x= =0) 

exit(1); 

z=x%16; 

x=x/16; 

gotoxy(y--,5); 

switch(z) 

{ 

Case 10: 

Printf(“A”); 

Break; 

Case 11: 

Printf(“%c”, „B‟); 

Break; 

Case 12: 

Printf(%c”, „C”); 

Break; 

Case 13: 

Printf(“D”); 

Break; 

Case 14: 

Printf(“E”); 

Break; 

Case 15: 

Printf(“F”); 

Default: 

Printf(“%d”, z); 

} 

} 

getch(); 

} 

Output: 

Enter the number: 31 

Conversion of decimal to Hexa decimal number 

1F