题解 | #X形图案#
X形图案
https://www.nowcoder.com/practice/83d6afe3018e44539c51265165806ee4
#include <stdio.h> #define N 20 int main() { int n = 0; while (1 == scanf("%d", &n)) { char arr[N][N] = { 0 }; int left = 0; int right = n - 1; while (left <= right) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { arr[i][j] = ' '; } arr[i][left] = '*'; arr[i][right] = '*'; left++; right--; } } // 输出 for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { printf("%c", arr[i][j]); } printf("\n"); } } return 0; }