forked from Ishaan28malik/Hacktoberfest-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Ishaan28malik#639 from ankita-04/patch-1
Added decimal to binary number converter using Stack
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |