Programming Examples

Write a program to convert decimal to hexadecimal number


Write a program to convert decimal to hexadecimal number?

Solution

#include<stdio.h>
# include <process.h>
void main()
{
int x,y=30,z;
clrscr();
printf(“\nEnter a number :”);
scanf(“%d”,&x);
printf(“\n Conversion of Decimal to Hexadecimal Number \n”);
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”);
 break;
 default :
 printf(“%d”,z);
 }
}
}
Output

OUTPUT:


Enter a number : 31

Conversion of Decimal to Hexadecimal Number

1F

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz