# 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):Decimal = 116 Octal = 78 Decimal = 12 Octal 10Example:

*The steps required to convert an Octal Number to Decimal Number 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 to Convert Octal to Decimal is as follows:*

/* C++ Program to Convert Octal Number to Decimal Number */ #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: