**Decimal to octal program in c** is decimal to octal conversion in c.

In this tutorial we are going to see what is decimal number, what is octal numbers, how to convert decimal to octal, c program to convert decimal to octal. Decimal to octal program 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 decimal to octal**

Decimal to binary conversion in c : We divide the decimal number by 8 And write down the reminder. do this until final result is 0.

**Decimal to octal formula : **

Simply divide binary number by 8 and write down reminder.

**Decimal to octal example**

**Concept you need to know from c**

1. While loop in c

2. Assignment and arithmetic operator in c

**Decimal to octal algorithm**

1. Start

2. Declare variable

3. Divide decimal number by 8 continuously

4. And store result as octal number

5. If final result is zero then stop

6. Print octal number

7. End

## Decimal to octal program in c

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<stdio.h> main() { int dec,temp,i,j=1,octal=0; printf("Enter the decimal number : "); scanf("%d",&dec); temp=dec; while(temp!=0) { i=temp%8; octal=octal+(i*j); temp=temp/8; j=j*10; } printf("Octal number : %d\n",octal); } |

**Output :**

**Explanation :-**

**1. Start with header files**

**2. Write a main function**

**3. Declare variables**

dec => to store decimal number

i, j, temp => temporary variable

octal => to store octal number

**4. Take decimal number input from user**

scanf(“%d”,&dec);

=> dec = 229

**5. Copy decimal number to temporary variable**

temp = dec

**6. Main logic begins to convert decimal to octal**

**7. To divide number till result is 0 we use while loop to write this condition**

while(temp!=0)

**While loop iteration 1 :**

229 != 0 this condition true while executed

i=temp%8 => i = 5

octal=octal+(i*j) => octal = 5

temp=temp/8 => temp = 28

j=j*10 => j = 10

**While loop iteration 2 :**

28 != 0 this condition true while executed

i=temp%8 => i = 4

octal=octal+(i*j) => octal = 45

temp=temp/8 => temp = 3

j=j*10 => j = 100

**While loop iteration 3:**

3 != 0 this condition true while executed

i=temp%8 => i = 3

octal=octal+(i*j) => octal = 345

temp=temp/8 => temp = 0

j=j*10 => j = 1000

**While loop iteration 4 :**

0 != 0 this condition false and while stop executing

**8. Print octal number**

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

=> octal number of 229 is 345

**Recommended posts **

## Leave a Reply