0
#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();


 }
2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by WaltP
0

this is an easy version


#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();


 }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.