C Programming
Computer Programming

C Program using function to Convert Decimal to Binary using function



Write a Program in C using function to Convert Decimal to Binary using function

\* C Program using function to Convert Decimal to Binary using function *\

# include < stdio.h >
# include < conio.h >
int   dec_bin( int ) ;
int   main( )
{

int ch, dec_num, hex_num ;
long bin_num ;
printf("\n Enter a decimal Number : " ) ;
scanf( "%d", &dec_num ) ;
dec_bin( dec_num ) ;
return 0 ;

}

int   dec_bin( int dec_num ) ;
{

int i, n, a[50], rem ;
n = 1 ;
while( dec_num > 0 )
{
      rem = dec_num%2 ;
      a[n] = rem ;
      dec_num = dec_num/2 ;
      n++ ;
}
printf(" Binary of Entred Decimal Number is :\n " ) ;
for( i = n-1; i>0 ; i-- )
      printf( " %d ",a[i] ) ;

}

Output of Program :

Output of C Program using function to Convert Decimal to Binary using function