C Online Compiler
Example: C program to convert binary number to octal Number
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C program to convert binary number to octal Number #include <stdio.h> #include <math.h> // It's main function of the program int main() { long long binary_num, temp_binary_num; int decimal_num, octal_num, i = 0; printf("Enter Binary Number: "); scanf("%lld", &temp_binary_num); binary_num = temp_binary_num; // Step-1 make conversion binary to decimal while (temp_binary_num != 0) { decimal_num += (temp_binary_num % 10) * pow(2, i); ++i; temp_binary_num /= 10; } i = 1; // Step-2 then make conversion decimal to octal while (decimal_num != 0) { octal_num += (decimal_num % 8) * i; decimal_num /= 8; i *= 10; } // Final output of the program printf("\n%lld (Binary Number) = %d (Octal Number)\n", binary_num, octal_num); return 0; }
11001010101
Output
Clear
ADVERTISEMENTS