代码
#include<stdio.h>
#include<math.h>
int n;
void init() {
printf("请输入n:");
scanf("%d", &n);
}
void output() {
int spot = 0;
int linecount = 0;
int midLine = n / 2;
int pos_1 = midLine;
int pos_2 = 2 * midLine - pos_1;
while (linecount < n) {
if (spot == pos_1) {
if (pos_1 != pos_2) {
printf("*");
spot++;
}
else {
printf("*");
linecount++;
spot = 0;
pos_1 = linecount > midLine ? pos_1 + 1 : pos_1 - 1;
pos_2 = 2 * midLine - pos_1;
printf("\n");
}
}
if (spot == pos_2) {
printf("*");
linecount++;
spot = 0;
pos_1 = linecount > midLine ? pos_1 + 1 : pos_1 - 1;
pos_2 = 2 * midLine - pos_1;
printf("\n");
}
else {
printf(" ");
spot++;
}
}
}
int main() {
init();
output();
return 0;
}
标签:int,spot,pos,空心,linecount,菱形,printf,循环,midLine
From: https://www.cnblogs.com/cony1/p/16897334.html