当前位置:网站首页>【C语言练习——打印上三角及其变形(带空格版)】
【C语言练习——打印上三角及其变形(带空格版)】
2022-06-25 18:29:00 【初学C语言者】
活动地址:毕业季·进击的技术er
夏日炎炎,热浪中我们迎来毕业季,这是告别,也是迈向新起点的开始。这是一个毕业的月份,每年看到很多毕业生都离校上班,在校生准备考试和暑假实习,都非常感慨,不管怎样,作为在校生,玩好的同时,还是要能够扎实的学习,打好坚实基础,从初学C语言开始,为后续的实习找工作做准备。
前言
前面已经在【C语言练习——打印上三角及其变形】练过打印上三角及其变形了。本文在此基础上,练习打印上三角及其变形(带空格版)。两者形式基本一样,只是符号之间差了一个空格。如下图所示:

1、打印上三角
1.1 上三角左对齐版(带空格版)
//打印上三角———左对齐版 带空格版—
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++)
{
printf("* ");
}
printf("\n");
}
}
return 0;
}
结果见下图:

1.2 上三角中间对齐版(带空格版)
//打印上三角———中间对齐版 带空格版—
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++)
{
printf("* ");
}
printf("\n");
}
}
return 0;
}
结果见下图:

1.3 上三角右对齐版(带空格版)
//打印上三角———右对齐版 带空格版—
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++)
{
printf("* ");
}
printf("\n");
}
}
return 0;
}
结果见下图:

总结
本文练习打印上三角其变形——带空格版,主要练习了:
- 外循环、内循环的应用
- 注意行数、空格数、符号*数之间的数学表达式
活动地址:毕业季·进击的技术er
边栏推荐
- Idea annotation color modification method (clear)
- JVM understanding
- El table highly adaptive
- 快手616战报首发,次抛精华引新浪潮,快品牌跃入热榜top3
- [in depth understanding of tcapulusdb technology] tcapulusdb model
- RMAN backup database_ Restart RMAN backup
- 网络安全检测与防范 测试题(一)
- Skills to master in advanced development
- Training of long and difficult sentences in postgraduate entrance examination day87
- RMAN备份数据库_重启RMAN备份
猜你喜欢
![[path planning] how to add moving objects to a path](/img/ff/2a6cc811078fa9b0f7a223f90fceac.jpg)
[path planning] how to add moving objects to a path

LeetCode力扣(剑指offer 26-30)26. 树的子结构 27. 二叉树的镜像 28. 对称的二叉树 29. 顺时针打印矩阵 30. 包含min函数的栈
![[in depth understanding of tcapulusdb technology] new models of tcapulusdb](/img/10/f94a5e1ebeaa803c754dd77351950f.png)
[in depth understanding of tcapulusdb technology] new models of tcapulusdb

03 runtime data area overview and threads

Current situation and development suggestions of China's green PPP project industry: the investment scale is expanding, and the existing problems need to be improved to further promote the healthy dev
![[deeply understand tcapulusdb technology] tcapulusdb import data](/img/31/4e33fafa090e0bb5b55e11978cdff8.png)
[deeply understand tcapulusdb technology] tcapulusdb import data
![[in depth understanding of tcapulusdb technology] form creation and approval of document acceptance](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[in depth understanding of tcapulusdb technology] form creation and approval of document acceptance

Command records of common data types for redis cli operations
![[deeply understand tcapulusdb technology] cluster management operation](/img/5f/f501f557171d438f7cc9cc4427f234.png)
[deeply understand tcapulusdb technology] cluster management operation

Dell r530 built in hot spare status change description
随机推荐
Favorite PHP debugging methods
TCP/IP 测试题(一)
Redis6
connect to address IP: No route to host
【深入理解TcaplusDB技术】创建游戏区
【深入理解TcaplusDB技术】TcaplusDB新增机型
Ruffian Heng embedded semimonthly issue 57
Pycharm 使用过程中碰到问题
In 2021, China's private equity market is growing, and the scale of private equity fund management reaches 19.78 trillion yuan [figure]
05 virtual machine stack
Overview and trend analysis of China's foreign direct investment industry in 2020 [figure]
Differences and relations between sequential table and array (easy to confuse), linear table and linked list
[in depth understanding of tcapulusdb technology] tcapulusdb operation and maintenance doc
TCP/IP 测试题(二)
Analysis of China's road freight volume, market scale and competition pattern in 2020 [figure]
[elt.zip] openharmony paper Club - memory compression for data intensive applications
Kwai 616 war report was launched, and the essence was thrown away for the second time to lead the new wave. Fast brand jumped to the top 3 of the hot list
JVM problem replication
[path planning] how to add moving objects to a path
网络安全检测与防范 测试题(四)