#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
int n,p,b,d=0,i=0;
cout<<"Enter the binary number : ";
cin>>n;
do
{
b=n%10;
if(b==1||b==0)
goto now;
else
{
cout<<"You haven't entered binary no.\n";
cout<<"Try again\n";
getch();
exit(0);
}
now:
p=b*pow(2,i);
d=d+p;
i++;
n/=10;
}while(n!=0);
cout<<"The num is decimal is "<<d<<endl;
getch();
return(0);
}
No comments:
Post a Comment