Showing posts with label Binary to Decimal Number. Show all posts
Showing posts with label Binary to Decimal Number. Show all posts

Write a C++ Program to Convert Binary into Decimal Number

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

Related Post

Array:
String functions:
General (Loops-for/while)
Write a Program to print reverse of a given number Write a Program to print Product of Digits (eg. 212=2*1*2=4) of a given number Write a C++ Program to Convert Binary into Decimal Number