- Home
- Course Category
- Course Result
- Course Detail
Hot Line: 0124-2383121
Course Introduction
Programs for practice
In the program below, we've Decimal to Hexadecimal Conversion in C++
Source Code: Convert Decimal number to HexaDecimal
/* C++ Program - Decimal to Hexadecimal Conversion */
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long int decnum, rem, quot;
char hexdecnum[100];
int i=1, j, temp;
cout<<"Enter any decimal number : ";
cin>>decnum;
quot=decnum;
while(quot!=0)
{
temp=quot%16;
// to convert integer into character
if(temp<10)
{
temp=temp+48;
}
else
{
temp=temp+55;
}
hexdecnum[i++]=temp;
quot=quot/16;
}
cout<<"Equivalent hexadecimal value of "<<decnum<<" is : \n";
for(j=i-1; j>0; j--)
{
cout<<hexdecnum[j];
}
getch();
}
Output
Enter any decimal number :45
Equivalent hexadecimal value of 45 is:
2D