代码
#include<stdio.h>
int n;
void init() {
printf("请输入n:");
scanf("%d", &n);
}
void output() {
int spot = 0;
int linecount = 0;
int mid = n / 2;
int pos_1 = mid;
int pos_2 = 2 * mid - pos_1;
while (linecount < n) {
if (spot == pos_1 || spot == pos_2) {
if (pos_1 == pos_2) {
linecount++;
printf("*");
spot = 0;
pos_1 = linecount > mid ? pos_1 + 1 : pos_1 - 1;
pos_2 = 2 * mid - pos_1;
printf("\n");
}
else {
if (spot == pos_1) {
printf("*");
spot++;
}
else {
linecount++;
printf("*");
spot = 0;
pos_1 = linecount > mid ? pos_1 + 1 : pos_1 - 1;
pos_2 = 2 * mid - pos_1;
printf("\n");
}
}
}
else {
printf(" ");
spot++;
}
}
}
int main() {
init();
output();
return 0;
}