-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversion_from_decimal.c
68 lines (57 loc) · 1.15 KB
/
conversion_from_decimal.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
#include <stdio.h>
void cbinary(int number) {
int binary[64];
int i = 0;
while (number> 0) {
binary[i] = number % 2;
number = number/2;
i++;
}
printf("Binary: ");
for (int j = i - 1; j >= 0; j--) {
printf("%d", binary[j]);
}
printf("\n");
}
void coctal(int number) {
int octal[64];
int i = 0;
while (number > 0) {
octal[i] = number % 8;
number=number/ 8;
i++;
}
printf("Octal: ");
for (int j = i - 1; j >= 0; j--) {
printf("%d", octal[j]);
}
printf("\n");
}
void chexadecimal(int number) {
char hexadecimal[32];
int i = 0;
char hex[] = "0123456789ABCDEF";
while (number > 0) {
hexadecimal[i] = hex[number % 16];
number=number/ 16;
i++;
}
printf("Hexadecimal: ");
for (int j = i - 1; j >= 0; j--) {
printf("%c", hexadecimal[j]);
}
printf("\n");
}
int main() {
int number;
scanf("%d",&number);
if(number<=0){
printf("Invalid Input");
}
else{
cbinary(number);
coctal(number);
chexadecimal(number);
}
return 0;
}