Program to convert octal to decimal in c is a octal to decimal conversion.

What is the decimal number?
Numbers we use in everyday life from 0 to 9 are the decimal numbers
What is the octal number?
A number expressed in base 8. The numbers from 0 to 7 are octal numbers.

How to convert octal to decimal
Octal to decimal conversion: write down the powers of eight start from right to left. Calculate the power of 8 for each digit. Write down the final value of each power of eight. Add the final values. This final result is our decimal number.

Octal to the decimal formula :
Decimal number = Add the power of 8 for each digit in an octal number.

Octal to decimal example

Octal to decimal

Octal to decimal algorithm

  1. Declare variable
  2. Find the power of eight for each digit start from right to left
  3. Calculate the power of eight
  4. Add final values
  5. Print decimal number

Program to convert octal to decimal in c

#include<stdio.h>
#include<math.h>
main()
{
int dec=0,temp,i,inc=0,octal;
printf("Enter octal number to convert to decimal number\n");
scanf("%d",&octal);
temp=octal;
while(temp!=0)
{
i=temp%10;
dec=dec+(i*pow(8,inc));
temp=temp/10;
inc++;
}
printf("Decimal number of %d is %d\n",octal,dec);
}

Output :

octal to decimal in c

Write A Comment