Skip to content

Commit

Permalink
Merge pull request Ishaan28malik#639 from ankita-04/patch-1
Browse files Browse the repository at this point in the history
Added decimal to binary number converter using Stack
  • Loading branch information
Ishaan28malik authored Oct 21, 2019
2 parents 2e94784 + 6221c5a commit c5eceb1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions binStack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "stdio.h"
#include "stdlib.h"
struct xx
{
int data;
struct xx *link;
};
struct xx *sp=0,*q;
main()
{
int n;
printf("Enter a decimal number :");
scanf("%d",&n);
while(n>0)
{
if(n==0)
{
sp=(struct xx *)malloc(sizeof(struct xx));
sp->data=n%2;
sp->link=0;
}
else
{
q=(struct xx *)malloc(sizeof(struct xx));
q->link=sp;
sp=q;
sp->data=n%2;
}
n=n/2;
}
while(sp!=0)
{
printf("%d ",sp->data);
sp=sp->link;
}
}

0 comments on commit c5eceb1

Please sign in to comment.