\* C Program using function to Convert Octal Number to Binary Number *\
# include < stdio.h >
# include < conio.h >
# include < math.h >
long octalToBinary( int octalnum ) ;
{
int decimalnum = 0, i = 0 ;
long binarynum = 0 ;
while( octalnum != 0 )
{
decimalnum = decimalnum + (octalnum%10) * pow( 8, i ) ;
i++ ;
octalnum = octalnum / 10 ;
}
i = 1 ;
while ( decimalnum != 0 )
{
binarynum = binarynum + (decimalnum % 2) * i ;
decimalnum = decimalnum / 2 ;
i = i * 10 ;
}
return binarynum ;
}
int main( )
{
int octalnum, k, count = 0 ;
printf("\n Enter an octal number: ") ;
scanf("%d", &octalnum) ;
k = octalnum ;
while( k > 0 )
{
int rem = 0 ;
rem = k % 10 ;
k = k / 10 ;
if( rem > 7 )
{
count = 1 ;
break ;
}
}
if( count == 1 )
printf(" Entered number %d is not a Octal number !", octalnum) ;
else
printf(" Equivalent binary number is: %ld", octalToBinary(octalnum)) ;
return 0 ;
}