#include<stdio.h>
#include<conio.h>
void main()
{
int i[15],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();
}
dmanjunath 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.