forked from Pranav016/Hacktoberfest-PR-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 11
/
decimal to hexa.c
95 lines (82 loc) · 1.62 KB
/
decimal to hexa.c
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<stdio.h>
#include<stdlib.h>
#define SIZE 10
#define TRUE 1
#define FALSE 0
/**********************************************/
struct stack
{
int TOP;
int Item [SIZE];
};
/**********************************************/
struct stack S;
/**********************************************/
void Initalize(void)
{
S.TOP=-1;
}
/**********************************************/
int Empty(void)
{
if(S.TOP==-1)
return TRUE;
else
return FALSE;
}
/**********************************************/
int Push( int x)
{
if(S.TOP== SIZE-1)
{
printf("stack overflow");
exit (1);
}
S.TOP=S.TOP+1;
S.Item[S.TOP]=x;
}
/**********************************************/
int Pop()
{
int x;
if(Empty())
{
printf("stack underflow");
exit(1);
}
x=S.Item[S.TOP];
S.TOP=S.TOP-1;
return x;
}
/**********************************************/
int decimaltohexa(int decimal)
{
char hexdecimal[100];
int r,x;
Initalize();
while (decimal!= 0)
{
r = decimal % 16;
if (r< 10)
Push(48 + r);
else
Push(55 + r);
decimal = decimal / 16;
}
while(!Empty())
{
x=Pop();
printf("%c",x);
}
}
/**********************************************/
int main()
{
int x;
int decimal;
printf("enter the decimal no");
scanf("%d",&decimal);
decimaltohexa(decimal);
//printf("\n\t%d",x);
}
/**********************************************/