题解 | #空心正方形图案#
空心正方形图案
http://www.nowcoder.com/practice/72347ee949dc47399186ee183632f303
#include<stdio.h>
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++) { //外循环行
for (int j = 1; j <= n; j++) { //内循环列
if (i == 1 || i == n || j == 1 || j == n) printf("* ");
else printf(" ");
}
printf("\n");
}
}
return 0;
}
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++) { //外循环行
for (int j = 1; j <= n; j++) { //内循环列
if (i == 1 || i == n || j == 1 || j == n) printf("* ");
else printf(" ");
}
printf("\n");
}
}
return 0;
}