当前位置:网站首页>[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
边栏推荐
- How to develop the language pack in the one-to-one video chat source code
- 独立站卖家都在用的五大电子邮件营销技巧,你知道吗?
- ? How to write the position to output true
- JS text box loses focus to modify width text and symbols
- 拉萨手风琴
- Lhasa accordion
- Opencv实现颜色检测
- Latest Windows version 5.0.14 of redis
- [JVM] - memory partition in JVM
- Carboxylic acid study: lumiprobe sulfoacyanine 7 dicarboxylic acid
猜你喜欢
JS 文本框失去焦点修改全半角文字和符号
[JVM] - Division de la mémoire en JVM
[untitled] drv8825 stepping motor drive board schematic diagram
Detailed usage configuration of the shutter textbutton, overview of the shutter buttonstyle style and Practice
Voltage mode and current mode control of switching power supply
MySQL 45 talk | 05 explain the index in simple terms (Part 2)
Binder面试之:内存管理单元
Amino dye research: lumiprobe fam amine, 6-isomer
[Verilog quick start of Niuke online question brushing series] ~ one out of four multiplexer
Animation de ligne
随机推荐
【JVM】——JVM中内存划分
Wireless sensor network learning notes (I)
JSP
A guide to P2P network penetration (stun) for metartc5.0 programming
Keil C51的Data Overlaying机制导致的函数重入问题
JS中的链表(含leetcode例题)<持续更新~>
Store inventory management system source code
拉萨手风琴
Office is being updated and the application cannot start normally
Programmer - Shepherd
Latest Windows version 5.0.14 of redis
What does mysql---where 1=1 mean
JSP connects with Oracle to realize login and registration (simple)
二级造价工程师证书含金量到底有多高?看这些就知道了
2022 Western pastry (Advanced) test question simulation test platform operation
[JVM] - memory partition in JVM
Share a powerful tool for factor Mining: genetic programming
Carboxylic acid study: lumiprobe sulfoacyanine 7 dicarboxylic acid
Dart学习——函数、类
The short video local life section has become popular. How to grasp the new opportunities?