#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int a[10],i,n,sum=0,j,k=0;
clrscr();
cout<<"Enter binary number : ";
cin>>n;
i=0;
while(n>0)
{
a[i]=n%10;
n=n/10;
i++;
}
for(j=0;j<i;j++)
{
sum=sum+a[j]*pow(2,k);
k++;
}
cout<<"Decimal number is : "<<sum;
getch();
}
No comments:
Post a Comment