Octal To Decimal Conversion

Octal to Decimal Conversion:-

It is easy to convert an octal number to decimal number. For this, the user is asked to enter an octal number which is converted to a decimal number following a series of steps. The algorithm below illustrates this process in a step wise process. It is then followed by a C program that converts an Octal number to a decimal number.

 

Read Also: Program for Palindrome Or Not

Octal to decimal conversion in C programming

Working:-

Step 1. Start

Step 2. An octal number is taken as an input from the user.

Step 3. Multiply each digit of the octal number starting from the last digit with powers of 8.

Step 4. Add all the digits multiplied.

Step 5. The total sum of the digits gives the decimal number.

Step 6. Stop

C program for Octal to Decimal Conversion

/** C Program to Convert Octal to Decimal */

#include<stdio.h> 
#include<math.h>

int main()
{
//Variable Initialization
    long int oct, dec = 0;
    int i = 0;
//Taking input from user
    printf("Enter an octal number: ");
    scanf("%ld", &oct);
//Conversion of octal to decimal
    while(oct != 0)
    {
        dec =  dec +(oct % 10)* pow(8, i++);
       //oct/=10;
oct = oct / 10;     }
//display     printf("Equivalent decimal number: %ld",dec);     return 0; }

 Output

Enter an octal number: 67
Equivalent decimal number: 55

Please Login/Signup to comment