Q)Write a C program to convert the BINARY NUMBER to OCTAL NUMBER
Sol)
#include<stdio.h>
int main( )
{
long int binary_no, octal_no=0, j=1, rem;
printf("Enter any Binary number: " ) ;
scanf("%ld", &binary_no) ;
while(binary_no!=0)
{
rem=binary_no%10 ;
octal_no=octal_no+rem*j ;
j=j*2;
binary_no=binary_no/10 ;
}
printf("Equivalent octal value: %ld", octal_no) ;
return 0;
}
use "%o" instead of %d...otherwise it will print decimal equivalent of the binary number...
ReplyDelete