C Program to Convert Octal Number to Decimal

In this program, you'll learn to convert Ocatl number to Decimal number system.

Decimal to binary in C: We can convert any decimal number (base-10 (0 to 9)) into binary number(base-2 (0 or 1)) by c program.

Decimal number is a base 10 number, there are total 10 digits between 0 to 9. Any combination of digits is decimal number such as 23, 445, 132, 0, 2 etc.

Octal number is a base 8 number contains only 8 digits either 0 through 7. Any combination of digits is octal number such as 116, 33, 133, etc.



Source Code
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int dec = 0, i, rem, c = 0;
    int oct;
    cout<<"Enter the Octal number: ";
    cin>>oct;

    while(oct > 0)
    {
        rem = oct % 10;
        dec = dec + rem * pow(8, c);
        oct = oct / 10;
        c++;
    }
    cout<<"Decimal Equivalent is: "<< dec;
    return 0;
}
Output
Enter the Octal number: 116
Decimal Equivalent is: 78

Enter the Octal number: 41
Decimal Equivalent is: 33