-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecimal_binary_stack.c
More file actions
58 lines (58 loc) · 936 Bytes
/
decimal_binary_stack.c
File metadata and controls
58 lines (58 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#define size 1000
typedef struct
{
int a[size];
int top;
} stack_type;
int initial(stack_type *v)
{
v->top = -1;
}
int overflow(stack_type *v)
{
if (v->top == size - 1)
return 0;
else
return 1;
}
int underflow(stack_type *v)
{
if (v->top == -1)
return 0;
else
return 1;
}
int push(stack_type *v,int a)
{
v->top++;
v->a[v->top] = a;
}
int pop(stack_type *v)
{
int temp = v->a[v->top];
v->top--;
return temp;
}
int main()
{
stack_type s;
initial(&s);
int n,a;
printf("Enter a number\n");
scanf("%d",&n);
while(n>0){
a=n%2;
push(&s,a);
n=n/2;
}
printf("The binary number is\n");
int t=underflow(&s);
int dis;
while(t!=0){
dis=pop(&s);
printf("%d",dis);
t=underflow(&s);
}
return 0;
}