You are on page 1of 1

C PROGRAM TO CONVERT BINARY NUMBER TO DECIMAL

May 13, 2010 by admin


Filed under: PREPARATION MATERIALS

/* Write a C program to convert the given binary number into decimal */


#include <stdio.h>
void main()
{
int num, bnum, dec = 0, base = 1, rem ;
printf( Enter a binary number(1s and 0s)\n );
scanf( %d , &num); /*maximum five digits */
bnum = num;
while( num > 0)
{
rem = num % 10;
dec = dec + rem * base;
num = num / 10 ;
base = base * 2;
}
printf( The Binary number is = %d\n , bnum);
printf( Its decimal equivalent is =%d\n , dec);
} /* End of main() */

You might also like