当前位置:网站首页>[C language practice - printing hollow square and its deformation]
[C language practice - printing hollow square and its deformation]
2022-06-28 05:28: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 squares and their deformations 】、【C Language practice —— Print the hollow lower triangle and its deformation 】、【C Language practice —— Print the upper triangle of the hollow and its deformation 】 Honed printing hollow upper triangle and its deformation 、 Print hollow triangles and their deformations 、 Print squares and their deformations .
On this basis , Practice printing hollow squares and their deformations
1、 Print a hollow square
1.1 graphics 1—— Blank free version
// Print a hollow square No spaces
int main()
{
int n = 0;
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)// Row number
{
for (int j = 0; j < n; j++)// Number of columns
{
// Output when conditions are met * , That is, on the boundary is *
if (i == 0 || j == 0 || i == n - 1 || j == n - 1)
printf("*");
else
printf(" ");// All points not on the boundary are spaces
}
printf("\n");
}
}
return 0;
}
The results are as follows :

1.2 graphics 2—— Blank version
// Print a hollow square Blank Edition
int main()
{
int n = 0;
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)// Row number
{
for (int j = 0; j < n; j++)// Number of columns
{
// Output when conditions are met * , That is, on the boundary is *
if (i == 0 || j == 0 || i == n - 1 || j == n - 1)
printf("* ");
else
printf(" ");// All points not on the boundary are spaces
}
printf("\n");
}
}
return 0;
}
The results are as follows :

1.3 graphics 3—— rotate 45 degree , No blank space version
// Print a square , rotate 45 degree , No blank space version
int main()
{
int n = 0;
while (scanf("%d", &n) != EOF)
{
// Print the top half n
for (int i = 0; i < n; i++)
{
// Print a row
// Print space
int j = 0;
for (j = 0; j < n - 1 - i; j++)
{
printf(" ");
}
// Print *
for (j = 0; j < 2 * i + 1; j++)
{
// Output when conditions are met * , That is, on the boundary is *
if (j == 0 || j == 2 * i )
printf("*");
else
printf(" ");// All points not on the boundary are spaces
}
printf("\n");
}
// Print the bottom half n-1
for (int i = 0; i < n - 1; i++)
{
// Print a row
// Print space
int j = 0;
for (j = 0; j <= i; j++)
{
printf(" ");
}
// Print *
for (j = 0; j < (n - 1 - i) * 2 - 1; j++)
{
// Output when conditions are met * , That is, on the boundary is *
if (j == 0 || j == (n - 1 - i) * 2 - 2)
printf("*");
else
printf(" ");// All points not on the boundary are spaces
}
printf("\n");
}
}
return 0;
}
The results are as follows :

1.4 graphics 4—— rotate 45 degree , Blank version
// Print a square , rotate 45 degree , Blank version
int main()
{
int n = 0;
while (scanf("%d", &n) != EOF)
{
// Print the top half n
for (int i = 0; i < n; i++)
{
// Print a row
// Print space
int j = 0;
for (j = 0; j < n - 1 - i; j++)
{
printf(" ");
}
// Print *
for (j = 0; j <= i; j++)
{
// Output when conditions are met * , That is, on the boundary is *
if (j == 0 || i == j)
printf("* ");
else
printf(" ");// All points not on the boundary are spaces
}
printf("\n");
}
// Print the bottom half n-1
for (int i = 0; i < n - 1; i++)
{
// Print a row
// Print space
int j = 0;
for (j = 0; j <= i; j++)
{
printf(" ");
}
// Print *
for (j = 0; j < (n - 1 - i); j++)
{
// Output when conditions are met * , That is, on the boundary is *
if (j == 0 || j == n - i - 2)
printf("* ");
else
printf(" ");// All points not on the boundary are spaces
}
printf("\n");
}
}
return 0;
}
}
The results are as follows :

summary
This article exercises printing hollow square and its deformation , 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
边栏推荐
- 2022 Western pastry (Advanced) test question simulation test platform operation
- How high is the gold content of grade II cost engineer certificate? Just look at this
- JS中的链表(含leetcode例题)<持续更新~>
- How to learn programmable logic controller (PLC)?
- Zzuli:1071 decomposing prime factor
- Operation of 2022 power cable judgment question simulation examination platform
- [Verilog quick start of Niuke online question brushing series] ~ one out of four multiplexer
- 二级造价工程师考试还没完?还有资格审核规定!
- MySQL 45讲 | 05 深入浅出索引(下)
- JS 文本框失去焦点修改全半角文字和符号
猜你喜欢

Docker installs mysql5.7 and starts binlog

JSP

Function reentry caused by Keil C51's data overlaying mechanism

What does mysql---where 1=1 mean

Dart学习——函数、类

Binder面试之:内存管理单元

【Linux】——使用xshell在Linux上安装MySQL及实现Webapp的部署

独立站卖家都在用的五大电子邮件营销技巧,你知道吗?

How to design an awesome high concurrency architecture from scratch (recommended Collection)

Online yaml to JSON tool
随机推荐
Biovendor sRAGE protein solution
sqlmap工具使用手册
拉萨手风琴
Docker安装Mysql5.7并开启binlog
mysql 导出查询结果成 excel 文件
Solution of dam safety automatic monitoring system for medium and small reservoirs
Store inventory management system source code
一看就会 MotionLayout使用的几种方式
It is the latest weapon to cross the blockade. It is one of the fastest ladders.
Install kubebuilder
Reactive dye research: lumiprobe af594 NHS ester, 5-isomer
Latest Windows version 5.0.14 of redis
Gorm transaction experience
codeforces每日5题(均1700)
jq图片放大器
TypeScript基础类型
OpenSSL client programming: SSL session failure caused by an obscure function
jsp连接oracle实现登录注册(简单)
To batch add background pictures and color changing effects to videos
Online yaml to JSON tool