-
Notifications
You must be signed in to change notification settings - Fork 0
/
deciToHexa.c
43 lines (40 loc) · 979 Bytes
/
deciToHexa.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
#include <stdio.h>
#include <string.h>
int hexa, top = -1;
char binStack[50];
void push(int val){
if (val < 10)
binStack[++top] = val + '0';
else{
switch(val){
case 10:
binStack[++top] = 'A';
break;
case 11:
binStack[++top] = 'B';
break;
case 12:
binStack[++top] = 'C';
break;
case 13:
binStack[++top] = 'D';
break;
case 14:
binStack[++top] = 'E';
break;
case 15:
binStack[++top] = 'F';
break;
}
}
}
void main(){
printf("Enter The Decimal Number: ");
scanf("%d", &hexa);
while(hexa != 0){
push(hexa % 16);
hexa = hexa / 16;
}
printf("\nHexadecimal Number: ");
printf("%s", strrev(binStack));
}