``````#include<stdio.h>
#include<conio.h>

void main()
{
int i,n,q,j;
clrscr();
printf("Enter the value of N:");
scanf("%d",&n);//an unsigned value
printf("\nBinary Val of %d=",n);
q=n;//initialize quotient to n
for(j=0;j<16;j++) i[j]=0;//initialize binary vector to zero
//calculate the binary Equivalent
j=15;//store the Remainder in reverse order
if(q!=0)
{
while(q!=1)
{
if(j>=0) i[j]=q%2;
j--;
q=q/2;
}
i[j]=1;

}
//print the Binary Equivalent
for(j=0;j<=15;j++) printf("%d ",i[j]);

getch();

}``````

## All 2 Replies

this is an easy version

``````#include<stdio.h>
#include<conio.h>

void main()
{
int i,n,q,j;
clrscr();
printf("Enter the value of N:");
scanf("%d",&n);//an unsigned value
printf("\nBinary Val of %d=",n);
q=n;//initialize quotient to n
for(j=0;j<16;j++) i[j]=0;//initialize binary vector to zero
//calculate the binary Equivalent
j=15;//store the Remainder in reverse order
if(q!=0)
{
while(q!=1)
{
if(j>=0) i[j]=q%2;
j--;
q=q/2;
}
i[j]=1;

}
//print the Binary Equivalent
for(j=0;j<=15;j++) printf("%d ",i[j]);

getch();

}``````

Bad code posted for no apparent reason. Should this thread be deleted?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.