adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C++ to Convert Hexadecimal to Decimal number Using Function

Program in C++ to Convert Hexadecimal to Decimal number Using Function



#include<iostream>
#include<string.h>
#include<iomanip>
 using namespace std;
  int HexaToDec(char *ch)
  {
     int i,base=1,temp,dec=0;
     i=strlen(ch)-1;
         while(i>=0)
         {
             if(ch[i]>='A'&&ch[i]<='F')
              temp=int(ch[i])-55;
              else
               temp=int(ch[i])-48;
            dec+=temp*base;
            base*=16;
            i--;
         }
       return (dec);
 }
 int main()
  {
    char ch[3]="1A";
    cout<<"Enter a Hexadecimal number:-";
    char hexa[100];
    cin>>hexa;
    cout<<"Decimal No.="<<HexaToDec(hexa);
   return 0;
  }
Output:-









Post a Comment

0 Comments