题解 | #菱形图案#
菱形图案
https://www.nowcoder.com/practice/8b935f8ffe99445dbd42494febd13e45
#include <stdio.h> int main() { int a; while (scanf("%d", &a) != EOF) { for (int i = 0; i <=a; i++) { //打印正三角,正三角行数比输入数多一 for (int j = 0; j <=a-i-1; j++) //打印空格,比要打印的个数少一,最后一个要打印 printf(" "); for (int k = 0; k <=i; k++) //打印*号,第几行就打几个是正序 printf("* "); printf("\n"); } for (int i = 0; i < a; i++) { //倒三角形,行数和输入数相等 for (int j = 0; j <= i; j++) //打印空格,第几行就打印几个空格 printf(" "); for (int k = 0; k < a-i; k++)//打印*号,随行数增加一次递减,k控制打印次数 printf("* "); printf("\n"); } } return 0; }