一、运行结果图
二、源代码
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>int main()
{//初始化变量值;int line = 0;int i = 0;int j = 0;//获取变量值;scanf("%d", &line);//循环打印上半部分;for (i = 0; i < line; i++){//循环打印空白;for (j = 0; j < line - 1 - i; j++){printf(" ");}//循环打印*;for (j = 0; j < 2 * i + 1; j++){printf("*");}//换行;printf("\n");}//循环打印下半部分;for (i = 0; i < line - 1; i++){//循环打印空白;for (j = 0; j <= i; j++){printf(" ");}//循环打印*;for (j = 0; j < 2 * (line - 1 - i) - 1; j++){printf("*");}//换行;printf("\n");}
}