main() { char b[50]; int i,p=0,v=0; long int d=0; clrscr(); printf("\n\n\t\tThis program will help you to find the decimal equivalent"); printf("\n\t\t\t\tof a given binary number."); printf("\n\n\t\t Enter number in front of the '->' prompt : "); printf("\n\n\t\t\t\t -> "); scanf("%s",b); for(i=0;b[i]!='\0'; ) { if((b[i]!='0')&&(b[i]!='1')) { clrscr(); printf("\n\n\n\n\n\n\n\n\t\t\t\t INPUT ERROR !"); printf("\n\n\n\t\t\tThe number entered is not binary !"); printf("\n\n\n\n\n\t\t Press any key to return to source file....."); getch(); exit(); } else i=i+1; } i=i-1; while(i>=0) { p=p*2; if(p==0) p=1; if(b[i]=='1') { v=p*1; d=d+v; i=i-1; } else i=i-1; } printf("\n\n\n\n\t\t\t\t - A N S W E R -"); printf("\n\n\t\t\tThe decimal equivalent of "); for(i=0;b[i]!='\0';i++) printf("%c",b[i]); printf(" is %d.",d); getch(); }