Wednesday 23 January 2013

Binary to Decimal conversion using c++


#include <iostream.h>
#include <conio.h>
void main()
{
int n,b,d,arr[10],ar[10],a[10];
cout<<"enter how many no"<<endl;
cin>>n;
b=0;
n--;
for(int i=n;i>=0;i--)
{
cout<<"enter binary no"<<endl;
cin>>arr[i];
b++;
}

n=1;
for(int i=0;i<=b;i++)
{
ar[i]=n;
n=n*2;}
b--;
for(int j=0;j<=b;j++)
{
a[j]=arr[j]*ar[j];
d=0;
for(int j=0;j<=b;j++)
d=d+a[j];}
cout<<"conversion="<<d<<endl;
getch();
}

0 comments:

Post a Comment