C Program to Convert binary number to decimal

C Program to Convert binary number to decimal 


binary number to decimal number conversion in C, C assignment to convert Binary to Decimal, Number convention in C language.


#include < stdio.h >
#include < conio.h > 

void main()
{
 long n,dec,mult,r,base; 
 clrscr();
 printf("\n Enter a base : ");
 scanf("%ld",&base);
 printf("\n Enter a number :");
 scanf("%ld",&n); 
 dec = 0;
 mult=1;
 printf("\n Decimal equivalent of base %ld number %ld is ",base,n);
 while ( n != 0 )
 {
  r = n % 10;
  n /= 10;
  r = r * mult;
  dec = dec + r;
  mult *= base;
 } // while
 printf("%ld",dec);
}
 

No comments:

Post a Comment