Martes, Oktubre 16, 2012

Write a program to convert decimal to hexadecimal number.

Output:
Enter the number: 31
Conversion of Decimal to Hexadecimal number
1F

Code:
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
Int x, y=30, z;
clrscr();
printf(“Enter the 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”);
default:
printf(%d”, z);
}
}
getch();
}

Walang komento:

Mag-post ng isang Komento