C Program to Convert Binary to Octal

Let’s understand how to to Convert Binary to Octal in C Programming Language.

C Program to Convert Binary to Octal

#include <stdio.h>

/*Learn C Programming at CodeAtGlance.com*/

int main()

{

    long int b_Num, oct_Num = 0, j = 1, rem;

    printf("Please enter the value for  binary number: ");

    scanf("%ld", &b_Num);

    while (b_Num != 0)

    {

        rem = b_Num % 10;

        oct_Num = oct_Num + rem * j;

        j = j * 2;

        b_Num = b_Num / 10;

    }

    printf("Equivalent octal: %lo", oct_Num);

    return 0;

}

 

Leave a Reply