Saturday, 29 August 2015

C program c program to convert binary to octal



C program c program to convert binary to octal

#include<stdio.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;
}
Sample output:
Enter any number any binary number: 1101
Equivalent hexadecimal value: 15

Leave a Reply

 
 

Labels

Blog Archive