当前位置:网站首页>[C exercise] print diamond
[C exercise] print diamond
2022-07-18 01:41:00 【Domeecky】
example : Input 8, Print the following diamond .( The number entered is the number of rows in the upper half of the diamond )

We can regard the diamond as two parts , Pictured .

At this time, we can print in two parts , Suppose the input number is line, Then the number of lines in the upper part is line, The number of lines in the following part is line -1.
The number of spaces printed on each line in the upper part is as follows :

The number of asterisks printed on each line in the upper part is as follows :

The number of spaces printed in the lower part is as follows :

The number of asterisks printed on each line in the lower part is as follows :

Based on these data , You can write the code .
#include<stdio.h>
int main()
{
int line = 0;
scanf("%d", &line);
// The first half
for (int i = 0; i < line; i++)
{
for (int j = 0; j < line-i-1; j++)
printf(" ");
for (int j = 0; j < 2*i+1; j++)
printf("*");
printf("\n");
}
// The second part of
for (int i = 0; i < line - 1; i++)
{
for (int j = 0; j < 1 + i; j++)
printf(" ");
for (int j = 0; j < 2*(line-1-i)-1; j++)
printf("*");
printf("\n");
}
return 0;
}边栏推荐
- Today's sleep quality record is 80 points
- [latex Chinese and English style & Bold] freely choose Chinese and English font styles, and set the bold and black degree of Chinese and English fonts
- matlab 疑问
- 容器介绍及总结
- Matlab bottom source code to realize image dynamic binarization
- 【LaTex 中英文样式&加粗】自由选择中英文字体样式,中英文字体粗黑程度设置
- System. Use of arraycopy and detailed explanation of parameter meaning
- C. K-beautiful Strings
- STM32 application development practice tutorial: application development of persistent storage of environmental parameters
- 云原生:Docker实践经验(三)Docker 上部署 MySQL8 主从复制
猜你喜欢

【C 练习】打印‘X’图形

今日睡眠质量记录80分

【C】 Const decorated pointer

STM32应用开发实践教程:环境光照强度监测的应用开发

redis持久化之aof

树莓派远程 桌面显示不全

C语言指针相关问题解析

Matlab bottom source code to realize image dynamic binarization

How can Volvo be confident to maintain "zero casualties" in traffic safety in the era of electrification?
![[C exercise] input the month and year, and calculate the number of days in the month](/img/41/11d02273e27eee3bf97815da03bca5.png)
[C exercise] input the month and year, and calculate the number of days in the month
随机推荐
Realizing Halcon scale with MATLAB low-level source code_ image_ Range (can be used for background segmentation)
Play with Nacos! Replace Eureka as configuration center and Registration Center
C语言(程序环境和预处理)
Redis入门介绍
Common vulnerability types of tcp/ip protocol
搜索结果页竞价广告展现升级,对SEO有什么影响?
2020CCPC秦皇岛 Exam Results(尺取)
计算方法工程数学第一节课Doolittle
C语言实现手机通讯录
[practice C] xiaolele walks up the steps
Reasons for persisting in writing
【HCIA】数通网络基础
反射面试
Detailed installation steps of mysql5.6 version
Common SQL statements, stored procedures and functions
读书的思考
【C】函数栈帧的创建和销毁
Calculation method engineering mathematics first lesson Doolittle
STM32 application development practice tutorial: application development of environmental light intensity monitoring
C语言指针相关问题解析