#include <stdio.h>

#include<conio.h>

void main()

{

int num, binary, decimal = 0, base = 1, rem;

clrscr();

printf(“Enter a binary number(1s and 0s) \n”);

scanf(“%d”, &num); /* maximum five digits due to range of integer */

binary = num;

while (num > 0)

{

rem = num % 10;

decimal = decimal + rem * base;

num = num / 10 ;

base = base * 2;

}

printf(“The Binary number is = %d \n”, binary);

printf(“Decimal equivalent is = %d \n”, decimal);

getch();

}

Output :-

Advertisements