Page

C program to convert binary to octal

#include<stdio.h>
#include<conio.h>

int main()
   {
   
    long int binaryNumber,octalNumber=0,j=1,remainder;

    printf("Enter any number any binary number: ");
    scanf("%ld",&binaryNumber);

    while(binaryNumber!=0){
         remainder=binaryNumber%10;
        octalNumber=octalNumber+remainder*j;
        j=j*2;
        binaryNumber=binaryNumber/10;
    }

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

    return 0;
}


OUTPUT

Enter any number any binary number: 1101
Equivalent hexadecimal value: 15

No comments:

Post a Comment