Binary to Decimal Conversion in C or C Program for Binary to Decimal Number?
#include<stdio.h>
#include<conio.h>
void main()
{
long int b_n,d_n=0,j=1,rem;
clrscr();
printf("Enter a binary number: ");
scanf("%ld",&b_n);
while(b_n!=0)
{
rem=b_n%10;
d_n=d_n+rem*j;
j=j*2;
b_n=b_n/10;
}
printf("Equivalent decimal Number : %ld",d_n);
getch();
}
Output:
Enter a Binary Number : 101
Equivalent Decimal Number : 5