#### C Programming

- Print integer
- Add & subtract
- Odd & even
- Multiply & divide
- Check vowels
- Letter grade program
- Leap year program
- Sum of digits
- Prime numbers
- Sum of numbers
- Find factorial
- Fibonacci series
- Fibonacci triangle
- Number triangle
- Alphabet triangle
- Armstrong numbers
- Palindrome numbers
- Swap number
- Reverse number
- Decimal to binary
- Assembly code in C
- Matrix multiplication
- HCF & LCM
- nCr & nPr
- Print pattern
- Floyd’s triangle
- Pascal triangle
- Count digits
- Strong numbers
- Perfect numbers
- Sum of natural number
- Binary to decimal
- Decimal to octal
- Octal to decimal
- Binary to octal
- Octal to binary
- Add using pointer
- Bubble sort
- Insertion sort
- Selection sort
- Quick sort
- Binary search
- Linear search
- Largest element of array
- Smallest element of array
- Reverse Array
- Variable size & limit
- ASCII value of character
- Sum of array elements
- Number of element in array
- Merge two array
- Insert element in array
- Delete element from array
- Add two matrix
- Transpose matrix
- Print string
- Reverse string
- Delete vowels
- Sort string
- Remove spaces
- Swap string
- Random numbers
- Print date & time
- Print IP address
- Shut down computer

## Binary to octal number conversion

Binary number is 2 based number where octal is the 8 based number. Binary to octal conversion and some programs related to that will be discussed here. In this C programming guide we will make some program to convert a number from binary to octal.

As we know, we can use the digits from 0 to 7 for writing any number in octal number system where we can use only 0 and 1 to write any number in binary number system. Here we will take the binary number as input from the user and the convert it to the equivalent octal number using C program. So, let’s see some program related to this.

We recommend you to learn if you don’t know how to convert binary to octal mathematically.

## C program to convert binary to octal

```
// c program to convert from binary to octal
#include <stdio.h>
#include <math.h>
int main(){
long c, biNum, oct = 0, deci = 0;
printf("Enter any binary number to convert here : ");
scanf("%ld", &biNum);
while(biNum != 0){
deci = deci + (biNum % 10) * pow(2, c);
c++;
biNum /= 10;
}
c = 1;
while (deci != 0){
oct = oct + (deci % 8) * c;
deci /= 8;
c *= 10;
}
printf("\nOctal equivalence is = %d\n", oct);
return 0;
}
```

### Output of binary to octal program

## Convert binary to octal using function in C

```
// convert binary to octal using function in C
#include <stdio.h>
#include <math.h>
int converter_b_to_o(long bin);
int main(){
long bi_num, oct_num;
printf("Enter binary number to convert here : ");
scanf("%ld", &bi_num);
printf("\nEquivalent octal is = %d\n", converter_b_to_o(bi_num));
return 0;
}
int converter_b_to_o(long bin){
int k = 0, oct = 0, deci = 0;
while(bin != 0){
deci = deci + (bin % 10) * pow(2, k);
k++;
bin /= 10;
}
k = 1;
while (deci != 0){
oct = oct + (deci % 8) * k;
deci /= 8;
k *= 10;
}
return oct;
}
```

### Program output

```
Enter binary number to convert here : 111011001
Equivalent octal is = 731
```

**Previous page**: **Octal to decimal**

**Next page**: **Octal to binary**

**Recommended for you**: