当前位置:网站首页>C: print the diamond
C: print the diamond
2022-08-09 07:45:00 【Gaoyou wu is less】
题目链接:菱形图案
#include<stdio.h>
int main()
{
//多组输入
int n = 0;
while ((scanf("%d", &n) != EOF))
{
int i = 0;
int j = 0;
//triangle above
for (i = 0;i < n;i++)
{
for (j = 0;j < n - i;j++)
{
printf(" ");
}
for (j = 0;j < i + 1;j++)
{
printf("* ");
}
printf("\n");
}
//A line in the middle
for (i = 0;i < n + 1;i++)
{
printf("* ");
}
printf("\n");
//triangle below
for (i = 0;i < n;i++)
{
for (j = 0;j < i + 1;j++)
{
printf(" ");
}
for (j = 0;j < n-i;j++)//每行打印的*Decrement line by line
{
printf("* ");
}
printf("\n");
}
}
return 0;
}
思路:The rhombus can be divided into3个部分,上三角,A horizontal line in the middle,下三角.
The only difference between the upper triangle and the lower triangle is that each row of the upper triangle * 增加,Lower triangle for each row * 减少
边栏推荐
猜你喜欢
随机推荐
一站制造项目及Spark核心面试 ,220808,,,
(error) NOAUTH Authentication required.
String类创建的对象在JVM中的内存分配和equals与==的区别
View log common commands
jmeter concurrency and some limitations of the press
解决pycharm每次新建项目都要重新pip安装一些第三方库等问题
vlucas/phpdotenv phpdotenv获取变量内容偶尔出现返回false
Lottie系列一:介绍与使用
差分约束-图论
Important news丨.NET Core 3.1 will end support on December 13 this year
es6 基础知识详解 变量 字符串 解构赋值 函数 对象 从入门到精通
sklearn数据预处理
Oracle 限制时将空值排除
EXCEL使用函数联调(find,mid,vlookup,xlookup)
接口测试概念
基于布朗运动的文本生成方法-LANGUAGE MODELING VIA STOCHASTIC PROCESSES
排序第二节——选择排序(选择排序+堆排序)(两个视频讲解)
yolov5 detects the number of labels in the dataset
Rsync常见错误
工信部等四部门推动绿色智能家居产品下乡