-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhex_to_bin.c
53 lines (44 loc) · 1.17 KB
/
hex_to_bin.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
#include <stdio.h>
#include <stdlib.h>
void fillBinaryArray(int binaryArray[][8], int n, int value) {
int top = 0, bottom = n - 1, left = 0, right = n - 1;
while (top <= bottom && left <= right) {
for (int i = left; i <= right; i++) {
binaryArray[top][i] = value;
}
top++;
for (int i = top; i <= bottom; i++) {
binaryArray[i][right] = value;
}
right--;
if (top <= bottom) {
for (int i = right; i >= left; i--) {
binaryArray[bottom][i] = value;
}
bottom--;
}
if (left <= right) {
for (int i = bottom; i >= top; i--) {
binaryArray[i][left] = value;
}
left++;
}
}
}
void printBinaryArray(int binaryArray[][8], int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%d ", binaryArray[i][j]);
}
printf("\n");
}
printf("\n");
}
int main() {
int binaryArray[8][8];
for (int i = 0; i < 2; i++) {
fillBinaryArray(binaryArray, 8, i);
printBinaryArray(binaryArray, 8);
}
return 0;
}