在屏幕上輸出圖案:ide
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> int main() { int line = 0; int i = 0; scanf_s("%d", &line); for (i = 0; i < line; i++) { int j = 0; for (j = 0; j < line - 1 - i; j++) { printf("%c", ' '); } for (j = 0; j < (2 * i) + 1; j++) { printf("%c", '*'); } printf("\n"); } for (i = line - 1; i>0; i--) { int j = 0; for (j = 1; j <= line - i; j++) { printf("%c", ' '); } for (j = 0; j < (2 * i) - 1; j++) { printf("%c", '*'); } printf("\n"); } system("pause"); return 0; }