# Octal to Decimal Conversion

Octal to Decimal Conversion” is one of the classic programming problem exercise. Here, we are given an Octal Number, entered by user and our task is to write a program to convert the given Octal number to its equivalent Decimal Number.

```Formula(Octal to Decimal Conversion):
Let Octal number have ‘n’ digits.
F(n) = (Last Digit)*pow(8,0) + (Second last digit)*pow(8,1) + … + (first digit)*(8,n-1).

Example (Octal to Decimal Conversion):
Decimal = 116
Octal = 78
Decimal = 12
Octal 10```

The steps required for Octal to Decimal Conversion is as follows:

1. Let iterator = 0 and Decimal = 0
2. Store the remainder when the Octal number is divided by 10.
3. Decimal = Decimal + remainder * pow(8,iterator).
4. Increment the iterator by 1.
5. Divide the octal number by 10.
6. Repeat the steps from 2 to 5 until the octal number is greater than 0.
7. Print the result.

#### C++ Program for Octal to Decimal Conversion is as follows:

```/* C++ Program for Octal to Decimal Conversion */
#include<bits/stdc++.h>
using namespace std;
int main()
{
/* Scan the Octal Number */
int Octal;
cout<<"Enter the Octal Number: ";
cin>>Octal;

/* Converting Octal to Decimal*/
int Decimal = 0;
int iterator = 0;
int temp = Octal;
while(temp!=0)
{
int remainder = temp % 10;
Decimal = Decimal + remainder * pow(8,iterator);
iterator++;
temp = temp / 10;
}

/*Printing the result */
cout<<"The Decimal of "<<Octal<<" is "<<Decimal;
}

```
```OUTPUT:
Enter the Octal Number: 12
The Decimal of 12 is 10```

Related Posts: