Q. Program convert binary number values (0,1) to decimal numbers. //INCLUDING LIBRARIES #include
#include #include <stdlib.h> //BEGINING OF PRODRAM void main() { clrscr();
// CLEARING THE SCREEN
// INITIALIZATION OF VARIABLES int d1,d2,d3,d4,d5,d6,no=1,sum; // GETTING 6 DIGIT BINARY NO FROM USER cout<<"\nEnter 6 digit Binary No: "; cin>>d1>>d2>>d3>>d4>>d5>>d6; // CONDITION TO CHECK BINARY NO if ((d1!=1&&d1!=0)||(d2!=1&&d2!=0)||(d3!=1&&d3!=0)||(d4!=1&&d4! =0)||(d5!=1&&d5!=0)||(d6!=1&&d6!=0)) { cout<<"\n\nThe Entered No is not Binary..."; getch(); exit(0); } //CONDITIONS FOR CALCULATION OF DECIMAL EQUIVALENT NO if (d6==1) sum=1; else if (d6==0) sum=0; no*=2; if (d5==1) sum=sum+no; no*=2; if (d4==1) sum=sum+no;
no*=2; if (d3==1) sum=sum+no; no*=2; if (d2==1) sum=sum+no; no*=2; if (d1==1) sum=sum+no; // OUTPUT OF PROGRAM cout<<"\n\nThe Decimal No is: "<<sum; //END OF PRGRAM getch(); }
Click the link below to see more examples URL: http://ravianeducation.blogspot.com E-Mail: [email protected] Farhan: 03008855006