**C program to convert octal to decimal** is a octal to decimal conversion.

In this tutorial we are going to see what is decimal number, what is octal numbers, how to convert octal to decimal, c program to convert octal to decimal, octal to decimal in c.

**What is decimal number**

A numbers we use in everyday life from 0 to 9 are the decimal numbers

**What is octal numbers**

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 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 decimal formula : **

Decimal number = Add the power of 8 for each digits in octal number.

**octal to decimal example **

**Concept you need to know from c**

1. While loop in c

2. Assignment and arithmetic operator in c

**Octal to decimal algorithm **

1. Start

2. Declare variable

3. Find power of eight for each digit start from right to left

4. Calculate power of eight

5. Add final values

6. Print decimal number

7. End

## C program to convert octal to decimal

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#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

**Explanation :**

**1. Start writing with header files**

**2. Write main function**

**3. Declare variable**

dec => to store decimal number

octal => to store octal number

i, inc , temp => temporary variable

**4. Take input octal number**

scanf(“%d”,&octal);

=> octal = 345

**4. Copy octal number to temporary variable**

=> temp= 345

**5. Main logic begins**

while(temp!=0)

**while loop iteration 1 :**

345 != 0 condition true loop executed

i=temp%10 => i = 5

dec=dec+(i*pow(8,inc)) => dec = 5

temp=temp/10 => temp = 34

inc++ => inc = 1

**while loop iteration 2 :**

34 != 0 condition true loop executed

i=temp%10 => i = 4

dec=dec+(i*pow(8,inc)) => dec = 37

temp=temp/10 => temp = 3

inc++ => inc = 2

**while loop iteration 3 :**

3 != 0 condition true loop executed

i=temp%10 => i = 3

dec=dec+(i*pow(8,inc)) => dec = 229

temp=temp/10 => temp = 0

inc++ => inc = 3

**while loop iteration 4 :**

0 != 0 condition false and loop execution stops

**6. Print decimal number**

printf(“Decimal number of %d is %d\n”,octal,dec);

=> Decimal number of 345 is 229

## Leave a Reply