Program in C++ to Convert Decimal to Hexadecimal number Using Function
#include<iostream> #include<conio.h> #include<string.h> using namespace std; void DecToHexa(int dec,char hexa[]) { int temp,i; i=0; while(dec!=0) { temp=dec%16; if(temp>=10) temp+=55; else temp+=48; hexa[i++]=temp; dec=dec/16; } strrev(hexa); } int main() { int dec; cout<<"Enter a No.:-"; cin>>dec; char hex[100]; DecToHexa(dec,hex); cout<<"HexaDecimal No.="<<hex; getch(); }
Output:-
0 Comments