C Programming
Computer Programming

C Program using function to Convert an octal Number to decimal



Write a Program in C using function to Convert an octal Number to decimal

\* C Program using function to Convert an octal Number to decimal *\

# include < stdio.h >
# include < conio.h >
long   long convertOctalToDecimal( int octalNumber ) ;
int   main( )
{

int octalNumber, count = 0, k ;
printf("\n Enter an octal number: ") ;
scanf( "%d", &octalNumber ) ;
k = octalNumber ;
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 !", octalNumber ) ;
else
      printf( " The decimal of octal number %d is : %lld ", octalNumber, convertOctalToDecimal(octalNumber) ) ;

return 0;

}

long   long convertOctalToDecimal( int octalNumber ) ;
{

int decimalNumber = 0, i = 0 ;

while( octalNumber != 0 )
{
      decimalNumber += ( octalNumber%10 ) * pow( 8, i ) ;
      ++i ;
      octalNumber/= 10 ;
}
i = 1 ;
return decimalNumber ;

}

Output of Program :

Output of C Program using function to Convert an octal Number to decimal