**The Program in **C++ to Convert Hexadecimal number to Octal number **is given below:**

```
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int decimalNum=0, octalNum[30], rem, i=0, len=0;
char hexDecNum[10];
cout<<"Hello Codeauri Family,Enter the Hexadecimal Number here to convert them into octal equivalent:\n ";
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<<"\nSorry, its an Invalid 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<<"Well, The Equivalent Octal Value is : \n";
for(i=(i-1); i>=0; i--)
cout<<octalNum[i];
cout<<endl;
return 0;
}
```

## Output:

Hello Codeauri Family,Enter the Hexadecimal Number here to convert them into octal equivalent:

5f

Well, The Equivalent Octal Value is :

137

## Pro-Tips**💡**

This code is a C++ program that converts a hexadecimal number (input by the user) to its equivalent octal value.

The program first converts the hexadecimal number to its decimal equivalent using mathematical operations,

then converts the decimal number to its octal equivalent using mathematical operations, and finally prints the octal equivalent of the hexadecimal number to the user.

The program also has error handling to check for invalid hex digits in the input.

**Learn C-Sharp ↗**

C-sharp covers every topic to learn about C-Sharp thoroughly.

**Learn C Programming ↗**

C-Programming covers every topic to learn about C-Sharp thoroughly.

**Learn C++ Programming↗**

**Learn C++ Programming↗**

C++ covers every topic to learn about C-Sharp thoroughly.