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

Wednesday, July 6, 2011

Program to convert the given decimal number to binary number.


#include<iostream.h>
#include<conio.h>
void main()
{
  clrscr();
  int n,num,t;
  int ar[15];
  for(int i=0;i<15;i++)
  {
    ar[i]=0;
  }
  cout<<"Enter the decimal number:"<<endl;
  cin>>n;
  num=n;
  t=0;
  while(n>0)
  {
    ar[t]=n%2;
    n=n/2;
    t++;
  }
  cout<<"The binary equivalent is "<<endl;
  for(int j=t-1;j>=0;j--)
  {
    cout<<ar[j];
  }
  getch();
}