From 89a49734041b2c1425414e2d99d732d97265a1b1 Mon Sep 17 00:00:00 2001 From: pitnqh5lc <3321198270@qq.com> Date: Sun, 20 Feb 2022 10:38:35 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=E8=BE=93=E5=87=BA=E8=8F=B1=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 输出菱形 | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 输出菱形 diff --git a/输出菱形 b/输出菱形 new file mode 100644 index 0000000..135d572 --- /dev/null +++ b/输出菱形 @@ -0,0 +1,50 @@ +输入一个数,输出菱形图案(*) +代码: +#include +int main() +{ + int n,i,j,k; + scanf("%d",&n); + for(i = 1;i <= n;i ++) + { + for(j = 1;j <= n-i;j ++) + { + printf(" "); + } + for(k = 1;k <= 2*i-1;k ++) + { + printf("*"); + } + printf("\n"); + } + for(i = n-1;i > 0;i --) + { + for(j = n-i;j > 0;j --) + { + printf(" "); + } + for(k = 2*i-1;k > 0;k--) + { + printf("*"); + } + printf("\n"); + } + return 0; +} +测试输入: 5 +输出结果: + * + *** + ***** + ******* +********* + ******* + ***** + *** + * + +-------------------------------- +Process exited after 1.397 seconds with return value 0 +请按任意键继续. . . +- 输出大小: 148.8388671875 KiB +- 编译时间: 0.19s