text: // C++ Program to Convert Hexadecimal to Octal
  
  #include<iostream>
  #include<math.h>
  using namespace std;
  int main()
  {
      int decimalNum=0, octalNum[30], rem, i=0, len=0;
      char hexDecNum[10];
      cout<<"Enter the Hexadecimal Number: ";
      cin>>hexDecNum;
      while(hexDecNum[i]!='\0')
      {
          len++;
          i++;
      }
      len--;
      i=0;
      while(len>=0)
      {
          rem = hexDecNum[len];
          if(rem>=48 && rem<=57)
              rem = rem-48;
          else if(rem>=65 && rem<=70)
              rem = rem-55;
          else if(rem>=97 && rem<=102)
              rem = rem-87;
          else
          {
              cout<<"\nInvalid Hex Digit!";
              cout<<endl;
              return 0;
          }
          decimalNum = decimalNum + (rem*pow(16, i));
          len--;
          i++;
      }
      i=0;
      while(decimalNum != 0)
      {
          octalNum[i] = decimalNum%8;
          i++;
          decimalNum = decimalNum/8;
      }
      cout<<"\nEquivalent Octal Value: ";
      for(i=(i-1); i>=0; i--)
          cout<<octalNum[i];
      cout<<endl;
      return 0;
  }
  