题解 | #空心正方形图案#
空心正方形图案
https://www.nowcoder.com/practice/72347ee949dc47399186ee183632f303
#include<stdio.h>
int main() {
int num = 0;
int h = 0;
int l = 0;
char arr[20][20];
while (scanf("%d", &num) != EOF) {
for (h = 0; h < num; h++) {
for (l = 0; l < 2 * num - 1; l++) {
if (h == 0 && l % 2 == 0 || h == num - 1 && l % 2 == 0 || l == 0 ||
l == 2 * num - 2) {
arr[h][l] = '*';
} else {
arr[h][l] = ' ';
}
printf("%c", arr[h][l]);
}
printf("\n");
}
}
return 0;
}