This C Program Converts the given Binary to Octal. Binary number is a number that can be represented using only two numeric symbols – 0 and 1. A number in base 2.Octal is a numbering system that uses eight digits, 0 to 7, arranged in a series of columns to represent all numerical quantities. Each column or place value has a weighted value of 1, 8, 64, 512, and so on, ranging from right to left.

Here is source code of the C program to Convert Binary to Octal. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C Program to Convert Binary to Octal`

`*/`

`#include <stdio.h>`

int main()

`{`

long int binarynum, octalnum = 0, j = 1, remainder;

printf("Enter the value for binary number: ");

scanf("%ld", &binarynum);

while (binarynum != 0)

`{`

remainder = binarynum % 10;

octalnum = octalnum + remainder * j;

j = j * 2;

binarynum = binarynum / 10;

`}`

printf("Equivalent octal value: %lo", octalnum);

return 0;

`}`

Output: $ cc pgm5.c $ a.out Enter the value for binary number: 10101 Equivalent octal value: 25

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics, go to C Programming Examples.