Here is my program in Turboc compiler(problem is described below it)
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
static int i,sum,s;
long unsigned int bin;
clrscr();
cout<<"enter a binary no.";
cin>>bin;
while(bin>0)
{
s=bin%10;
bin=bin/10;
sum=sum+s*pow(2,i);
i=i+1;
}
cout<<"The decimal no.is"<<sum;
getch();
}
although it works well
for considerable range of binary no.s
but gives different result for 111 and 0111
thus it cant be used in larger program as module to decode BCD
the zero before every binary no. gives wrong answer which should not happen as
zeros should be washed out.