Decimal number to its corresponding Hexadecimal, Program in C++ Decimal number to its corresponding Hexadecimal
Write a C++ program to convert a Decimal number to its corresponding Hexadecimal number.

Program Code:
#include<iostream>
using namespace std;
int main()
{
long int deci, rem, q;
char hexa[100];
int i=1, j, temp;

cout<<"Enter any decimal number : ";
cin>>deci;
cout<<endl;
q = deci;
while(q != 0)
{
temp = q % 16;
if(temp < 10)
{
temp = temp + 48;
}
else
{
temp = temp + 55;
}
hexa[i++] = temp;
q = q / 16;
}
cout<<"Equivalent hexadecimal value of "<<deci<<" is : ";
for(j=i-1; j>0; j--)
{
cout<<hexa[j];
}
return 0;

The program output is tested on www.jdoodle.com
Output:
Enter any decimal number : 45
Equivalent hexadecimal value of 45 is : 2D


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: