当前位置:网站首页>[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
边栏推荐
猜你喜欢

jsp连接Oracle实现登录注册

2022 safety officer-b certificate examination question bank and answers

Quartus replication IP core

A guide to P2P network penetration (stun) for metartc5.0 programming

Function reentry caused by Keil C51's data overlaying mechanism

二级造价工程师考试还没完?还有资格审核规定!

【Linux】——使用xshell在Linux上安装MySQL及实现Webapp的部署
![[JVM series] JVM tuning](/img/e1/086f76ec6c9b56d97430b1e073f5a6.png)
[JVM series] JVM tuning

sklearn 特征工程(总结)

Latest Windows version 5.0.14 of redis
随机推荐
CSCI GA scheduling design
MySQL export database dictionary to excel file
证明素数/质数有无限多个
中小型水库大坝安全自动监测系统解决方案
Line animation
Gorm transaction experience
The heading angle of sliceplane is the same as that of math Corresponding transformation relation of atan2 (y, x)
Linked list in JS (including leetcode examples) < continuous update ~>
Performance degradation during dpdk source code testing
解决ValueError: Iterable over raw text documents expected, string object received.
Binder面试之:内存管理单元
Yunda's cloud based business in Taiwan construction 𞓜 practical school
How does guotaijun charge for safe varieties? Let's talk about the futures account opening process
Study on chemical properties and technology of biovendor rage ELISA Kit
sklearn 特征工程(总结)
Zzuli:1071 decomposing prime factor
一看就会 MotionLayout使用的几种方式
Liuhaiping's mobile phone passes [[uiapplication sharedapplication] delegate] window. safeAreaInsets. The height of the bottom security zone is 0
Object detection with OpenCV
电子邮件营销的优势在哪里?为什么shopline独立站卖家如此重视?