C program to convert a binary number to an octal number
belongs to collection: Number System Conversion Programs in C programming Language
All Answers
total answers (1)
belongs to collection: Number System Conversion Programs in C programming Language
total answers (1)
Here, we will read a number in binary format (0s and 1s) from the user and convert it to an octal number, and print it on the console screen.
Program:
The source code to convert a binary number to an octal number is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
Output:
Explanation:
Here, we created 4 integer variables binaryNumber, octalNumber, i, rem that are initialized with 0. Then we read a number in binary format (1s and 0s). Then we converted the number into a decimal number and printed the corresponding octal number using the "%o" format specifier on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer