#include <stdio.h> void Print(int h, int e) //打印一行 { for (int i = 0; i < h; i++) { printf(" "); } printf("*"); for (int i = 0; i < e - (h+1); i++) { printf(" "); } printf("*\n"); } int main() { int n = 0; while(scanf("%d", &n) != EOF) { for (int i = 0; i < n/2; i++) //打印上三角 { Print(i, n-1-i); } if (n % 2 != 0) { for (int i = 0; i < n/2; i++) { printf(" "); } printf("*\n"); } for (int i = n/2 - 1; i >= 0; i--) 打印下三角 { Print(i, n-1-i); } } return 0; }