Earn without any Investment!

Saturday, November 13, 2010

Binary to decimal

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
 clrscr();
 int p,q,r,bi[20];
 long num;
 cout<<"Enter Binary number:";
 cin>>num;
 p=0;
 while(num>0)
 {
  bi[p]=num%10;
  num=num/10;
  p++;
 }
 q=p-1;
 r=0;
 while(q>=0)
 {
  r=r+(bi[q]*pow(2,q));
  q--;
 }
 cout<<r;
 getch();
}

No comments:

Post a Comment