题解 | #X形图案#
X形图案
https://www.nowcoder.com/practice/83d6afe3018e44539c51265165806ee4
#include <stdio.h> int main() { int n; while (scanf("%d", &n) != EOF) { // 注意 while 处理多个 case // 64 位输出请用 printf("%lld") for (int i = 0; i < n; i++) { if (i < (n + 1) / 2) { int num = i; while (num--) { printf(" "); } printf("*"); num = n - (2 * (i + 1)); for (int i = num; i > 0; i--) { printf(" "); } if (num >= 0) { printf("*"); } printf("\n"); } else { int j = i + 1; int num = n - j; while (num--) { printf(" "); } printf("*"); num = n - 2 * (n - i); while (num--) { printf(" "); } printf("*\n"); } } } return 0; }