.#include <iostream>
using namespace std;
void main()
{
long int decn,rmd,q,dn=0,m,l;
int i=1,j,tmp;
char s;
cout<<"Convert Decimal to Hexadecimal:\n ";
cout<<"Input any Decimal number: ";
cin>>decn;
q = decn;
for(l=q;l>0;l=l/16)
{
tmp = l % 16;
if( tmp < 10)
tmp =tmp + 48; else
tmp = tmp + 55;
dn=dn*100+tmp;
}
cout<<"\nThe equivalent Hexadecimal Number : ";
for(m=dn;m>0;m=m/100)
{
s=m % 100;
cout<<s;
}
cout<<endl;
system ("pause");
}
Test Data :
Input any Decimal number: 79
Expected Output :
The equivalent Hexadecimal Number : 4F
using namespace std;
void main()
{
long int decn,rmd,q,dn=0,m,l;
int i=1,j,tmp;
char s;
cout<<"Convert Decimal to Hexadecimal:\n ";
cout<<"Input any Decimal number: ";
cin>>decn;
q = decn;
for(l=q;l>0;l=l/16)
{
tmp = l % 16;
if( tmp < 10)
tmp =tmp + 48; else
tmp = tmp + 55;
dn=dn*100+tmp;
}
cout<<"\nThe equivalent Hexadecimal Number : ";
for(m=dn;m>0;m=m/100)
{
s=m % 100;
cout<<s;
}
cout<<endl;
system ("pause");
}
Test Data :
Input any Decimal number: 79
Expected Output :
The equivalent Hexadecimal Number : 4F
Write a program in C++ to convert a decimal number to hexadecimal
Reviewed by Unknown
on
June 20, 2017
Rating:
No comments: