Wednesday, July 6, 2011

Program to convert the given binary number to a decimal number


#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
  clrscr();
  int n,num,t,d=0;
  cout<<"Enter the binary number:"<<endl;
  cin>>n;
  num=n;
  t=0;
  while(n>0)
  {
        d+=pow(2,t)*(n%10);
        n=n/10;
        t++;
  }
  cout<<"The decimal equivalent is"<<d<<endl;
  getch();
}

No comments:

Post a Comment