Wednesday, September 28, 2016

Decimal To Hexadecimal Conversion

Program To Convert Decimal Number To Hexadecimal Number:


#include<iostream>
using namespace std;
main()
{
int num,hexa[50],i=0;
cout<<"\nEnter Any Decimal Number ";
cin>>num;
while(num>0)
{
hexa[i]=num%16;
num=num/16;
i++;
}
cout<<"\nHexadecimal Equivalent is ";
for(int j=i-1;j>=0;j--)
{
switch(hexa[j])
{
case 10:
cout<<"A";
break;
case 11:
   cout<<"B";
break;
case 12:
   cout<<"C";
break;
case 13:
   cout<<"D";
break;
case 14:
   cout<<"E";
break;
case 15:
   cout<<"F";
break;
default:
cout<<hexa[j];
}}
}
Also See Program To Convert Decimal TO Octal Click Here

Output: