-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ9.c
42 lines (33 loc) · 931 Bytes
/
Q9.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
#include <stdio.h>
// Function to print binary equivalent
void printBinary(int num) {
int bits = sizeof(int) * 8; // Number of bits in an integer
for (int i = bits - 1; i >= 0; i--) {
printf("%d", (num >> i) & 1);
}
printf("\n");
}
// Function to print octal equivalent
void printOctal(int num) {
printf("%o\n", num);
}
// Function to print hexadecimal equivalent
void printHexadecimal(int num) {
printf("%x\n", num);
}
int main() {
int num;
// Accept an integer number from the user
printf("Enter an integer number: ");
scanf("%d", &num);
// Print binary equivalent
printf("Binary equivalent: ");
printBinary(num);
// Print octal equivalent
printf("Octal equivalent: ");
printOctal(num);
// Print hexadecimal equivalent
printf("Hexadecimal equivalent: ");
printHexadecimal(num);
return 0;
}