# Binary Equivalent Of Decimal Number Using Linked list

In this program i had just extracted the modulo of the number given,and keep on adding it in linklist. later on,i reversed the link list and displayed the result.
By:--

Anurag Pareek

``````/////////////////////////////////////////////////////////////////////
//////////////        Programmer : Anurag Pareek         ///////////
///////////////////////////////////////////////////////////////////

# include<stdio.h>
# include<alloc.h>
struct binary
{  int data;
};
void append(struct binary **,int);
void reverse(struct binary**);
void display(struct binary *);
void main()
{  int num,a;
struct binary *p;
p=NULL; /* empty list */
printf("Enter Any Number : ");
scanf("%d",&num);
while(num != 0)
{  a=num % 2 ;
append(&p,a);
num /=2;
}
reverse(&p);
printf("The Binary Equivalent is : ");
display(p);
}

void append(struct binary **q,int num)
{   struct binary *temp,*r;
temp = *q;
if(*q==NULL)
{   temp = (struct binary *)malloc(sizeof(struct binary));
temp->data=num;
*q=temp;
}
else
{  temp = *q;
}
r = (struct binary *)malloc(sizeof(struct binary));
r->data=num;
}
}

void reverse(struct binary **x)
{ struct binary *q,*r,*s;
q = *x;
r=NULL;
while(q !=NULL)
{  s=r;
r=q;
}
*x=r;
}

void display(struct binary *q)
{  while(q!=NULL)
{ printf("%d",q->data);