当前位置:网站首页>[C language practice - printing hollow upper triangle and its deformation]
[C language practice - printing hollow upper triangle and its deformation]
2022-06-26 15:27:00 【Beginners of C language】
Active address : Graduation season · The technique of attack er
It's hot in summer , We welcome the graduation season in the heat wave , This is farewell , It is also the beginning of a new starting point . This is the month of graduation , Every year I see many graduates leave school to work , Students prepare for exams and summer internships , Very emotional , No matter what , As a student in school , While playing well , Still want to be able to learn in a down-to-earth way , Lay a solid foundation , From the beginning C Beginning of language , Prepare for the follow-up internship .
List of articles
Preface
The front is already in 【C Language practice —— Print the upper triangle and its deformation 】 、【C Language practice —— Print the upper triangle and its deformation ( Blank version )】 、【C Language practice —— Print the hollow lower triangle and its deformation 】 Practiced printing upper triangle and its deformation 、 Print the hollow triangle and its deformation .
On this basis , Practice printing hollow upper triangles and their deformations , As shown in the figure below : They are the blank free versions of the upper triangle 、 Blank version 、 Hollow version
1、 Print white top triangle
1.1 Hollow upper triangle left aligned version
// Print white top triangle ——— Left aligned version
int main()
{
int n = 0;
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)
{
int j = 0;
for (j = 0; j < n - i; j++)
{
// Output when conditions are met * , That is, on the boundary is *
if (i == 0 || j == 0 || j == n - i - 1 )
printf("* ");
else
printf(" ");// All points not on the boundary are spaces
}
printf("\n");
}
}
return 0;
}
The results are as follows :
1.2 Hollow upper triangle middle aligned version
// Print white top triangle ——— Middle aligned version
int main()
{
int n = 0;
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)
{
int j = 0;
for (j = 0; j <= i; j++)
{
printf(" ");
}
for (j = 0; j < n - i; j++)
{
// Output when conditions are met * , That is, on the boundary is *
if (i == 0 || j == 0 || j == n - i - 1 )
printf("* ");
else
printf(" ");// All points not on the boundary are spaces
}
printf("\n");
}
}
return 0;
}
The results are as follows :
1.3 White upper triangle right aligned version
// Print white top triangle ——— Right aligned version
int main()
{
int n = 0;
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)
{
int j = 0;
for (j = 0; j <= 2 * i; j++)
{
printf(" ");
}
for (j = 0; j < n - i; j++)
{
// Output when conditions are met * , That is, on the boundary is *
if (i == 0 || j == 0 || j == n - i - 1)
printf("* ");
else
printf(" ");// All points not on the boundary are spaces
}
printf("\n");
}
}
return 0;
}
The results are as follows :
summary
In this paper, we practice printing the deformation of the upper triangle of the hollow , Mainly practice :
- Outer loop 、 Application of internal circulation
- Pay attention to the number of lines 、 Space number 、 Symbol * Mathematical expressions between numbers
Active address : Graduation season · The technique of attack er
边栏推荐
- Cluster addslots establish a cluster
- 【TcaplusDB知识库】TcaplusDB常规单据介绍
- Evaluate:huggingface detailed introduction to the evaluation index module
- Learning memory barrier
- JS之手写 bind、apply、call
- 【ceph】mkdir|mksnap流程源码分析|锁状态切换实例
- Summer camp is coming!!! Chongchongchong
- [tcapulusdb knowledge base] tcapulusdb doc acceptance - create business introduction
- 评价——TOPSIS
- Vsomeip3 dual computer communication file configuration
猜你喜欢
Function: crypto JS encryption and decryption
High frequency interview 𞓜 Flink Shuangliu join
Using restcloud ETL shell component to schedule dataX offline tasks
English grammar_ Adjective / adverb Level 3 - original sentence pattern
[tcapulusdb knowledge base] Introduction to tcapulusdb data structure
SQLite loads CSV files and performs data analysis
乐鑫 AWS IoT ExpressLink 模组达到通用可用性
【SNMP】snmp trap 介绍、安装、命令|Trap的发送与接收代码实现
Notes on brushing questions (19) -- binary tree: modification and construction of binary search tree
Redis cluster
随机推荐
Vsomeip3 dual computer communication file configuration
【ceph】mkdir|mksnap流程源码分析|锁状态切换实例
Optimizing for vectorization
HR export data Excel VBA
Unity C # e-learning (VIII) -- www
夏令营来啦!!!冲冲冲
1. accounting basis -- several major elements of accounting (general accounting theory, accounting subjects and accounts)
On which platform is it safe to buy shares and open an account? Ask for guidance
Applet: uniapp solves vendor JS is too large
一键安装gcc脚本
There are so many vulnerabilities in tcp/ip protocol?
RestCloud ETL抽取动态库表数据实践
功能:crypto-js加密解密
Particle filter PF -- Application in maneuvering target tracking (particle filter vs extended Kalman filter)
设计人员拿到的工程坐标系等高线CAD图如何加载进图新地球
RestCloud ETL抽取動態庫錶數據實踐
[CEPH] cephfs internal implementation (IV): how is MDS started-- Undigested
【TcaplusDB知识库】TcaplusDB数据构造介绍
SQLite loads CSV files and performs data analysis
Is the QR code for account opening given by the manager of the securities firm safe? Who can I open an account with?