-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverter.c
More file actions
50 lines (37 loc) · 957 Bytes
/
coverter.c
File metadata and controls
50 lines (37 loc) · 957 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
#include <stdio.h>
void convertToBinary(int decimalNum) {
printf("Binary equivalent: ");
if (decimalNum == 0) {
printf("0");
return;
}
int binaryNum[32];
int i = 0;
while (decimalNum > 0) {
binaryNum[i] = decimalNum % 2;
decimalNum /= 2;
i++;
}
for (int j = i - 1; j >= 0; j--) {
printf("%d", binaryNum[j]);
}
printf("\n");
}
void convertToOctal(int decimalNum) {
printf("Octal equivalent: %o\n", decimalNum);
}
void convertToHexadecimal(int decimalNum) {
printf("Hexadecimal equivalent: %X\n", decimalNum);
}
int main() {
int decimalNum;
scanf("%d", &decimalNum);
if (decimalNum <= 0) {
printf("Error: Value should be greater than 0");
return 0;
}
convertToBinary(decimalNum);
convertToOctal(decimalNum);
convertToHexadecimal(decimalNum);
return 0;
}