Sunday, February 15, 2015

C Program to convert a decimal number to binary number


#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int d,n,i,j,a[50];

cout<<"Enter a number:";
cin>>n; cout<<"
The binary conversion of "<<n<<" is 1";
for(i=1;n!=1;++i)
{
d=n%2;
a[i]=d;
n=n/2;
}

for(j=i-1;j>0;--j)
cout<<a[j];

getch();

}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.