programming-examples/c/_Basic/C program for Binary to decimal conversion.c

16 lines
378 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
/*binary to decimal conversion:*/
#include<stdio.h>
void main()
{
long int bn,dn=0,j=1,remainder;
printf("Enter any number any binary number: ");
scanf("%ld",&bn);
while(bn!=0)
{
remainder=bn%10;
dn=dn+remainder*j;
j=j*2;
bn=bn/10;
}
printf("Equivalent decimal value: %ld",dn);
}