-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
52 lines (39 loc) · 833 Bytes
/
main.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
#include <stdio.h>
int factorial(int max) {
int total = 1;
if (max != 0) {
int count;
for (count = 1; count <= max; count++) {
total *= count;
}
}
return total;
}
int permutation(int m, int n) {
return factorial(m) / factorial(m - n);
}
int combination(int m, int n) {
return permutation(m, n) / factorial(n);
}
void print_binary(int x) {
char binary[sizeof(int) * 8 + 1];
int i;
for (i = sizeof(int) * 8 - 1; i >= 0; i--) {
binary[i] = (x & 1) ? '1' : '0';
x >>= 1;
}
binary[sizeof(int) * 8] = '\0';
printf("%s\n", binary);
}
int main() {
int hi;
hi = -2147483648;
print_binary(hi);
hi = ~ hi;
print_binary(hi);
hi = -1;
print_binary(hi);
hi = ~hi;
print_binary(hi);
return 0;
}