# 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.

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

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

- Let iterator = 0 and Decimal = 0
- Store the remainder when the Octal number is divided by 10.
- Decimal = Decimal + remainder * pow(8,iterator).
- Increment the iterator by 1.
- Divide the octal number by 10.
- Repeat the steps from 2 to 5 until the octal number is greater than 0.
- 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;
}
```

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

**Related Posts:**

- Program to convert octal number to binary number.
- Program to convert octal number to hexadecimal number.
- Program to convert decimal number to binary number.
- Program to convert decimal number to octal number.
- Program to convert decimal number to hexadecimal number.
- Program to convert hexadecimal number to binary number.
- Program to convert hexadecimal number to octal number.
- Program to convert hexadecimal number to decimal number.
- Program to convert binary number to octal number.
- Program to convert binary number to decimal number.
- Program to convert binary number to hexadecimal number.
- Program to find Quotient and Remainder.
- Program to find largest amongst three numbers.
- Program to find factorial of a number.
- Program to find GCD of two numbers.
- Program to find LCM of two numbers.
- Program to check whether entered number is odd or even.
- Program to check whether entered number is prime number or not.
- Program to check whether entered number is palindrome or not.
- Program to check whether entered number is Armstrong Number or Not.