Pages

Monday 21 March 2011

PROGRAM TO CONVERT DECIMAL NUMBER TO BINARY

DESCRIPTION-:This program receive input as decimal number and then calculate its binary equivalent and then display the binary equivalent of that decimal number.
FOR EXAMPLE-:If we have input decimal number------
                                          23
Then it generate output as-----------------
                                       10111
                           
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i=0,j,d,a[10];
cout<<"enter the decimal number";
cin>>d;
while(d>0)
{
a[i]=d%2;
d=d/2;
i++;
}
cout<<"its binary equivalent is";
for(j=i-1;j>=0;j--)
{
cout<<a[j];
}
getch();
}

0 comments:

Post a Comment

 
Copyright (c) 2010 Concepts Of C++. Design by WPThemes Expert

Blogger Templates and RegistryBooster.