main() { char b[50]; int i,p=0,v=0,x=1; long int d=0,display=1; clrscr(); while(x!=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\tType 0 to Exit and 1 to Continue : "); scanf("%d",&x); switch(x) { case 1: 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'; ) { i=i+1; if((b[i]!='1')&&(b[1]!=0)) display=0; else display=1; if(display==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(); break; case 0: printf("\n\n\n\n\n\n\n\n\t\t\t\tPROGRAM TERMINATED !"); printf("\n\n\n\t\t\tPress any key to return to source file....."); default: clrscr(); printf("\n\n\n\n\n\n\n\n\t\t\t\tINVALID INPUT !"); printf("\n\n\n\t\t\tPress any key to continue....."); getch(); break; } else { clrscr(); printf("\n\n\n\n\n\n\n\n\t\t\t\tINPUT ERROR !"); printf("\n\n\n\t\t\tThe number is not binary !"); printf("\n\n\n\n\t\t\tPress any key to continue....."); getch(); break; } } } } }