当前位置:网站首页>【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
边栏推荐
- Favorite PHP debugging methods
- Analysis on the market scale and pattern of contrast agents in China in 2021: Jiangsu Hengrui pharmaceutical, general electric, Yangzijiang Pharmaceutical Group, Bayer and bleco account for more than
- Hash of redis command
- 【深入理解TcaplusDB技术】Tmonitor后台一键安装
- Skills to master in advanced development
- Basic operations and basic data types of MySQL database
- . How to exit net worker service gracefully
- Leetcode force buckle (Sword finger offer 26-30) 26 Substructure of tree 27 Image of binary tree 28 Symmetric binary tree 29 Print matrix 30 clockwise Stack containing min function
- 【深入理解TcaplusDB技术】单据受理之建表审批
- LeetCode 322. Change exchange & dynamic planning
猜你喜欢

SVN介绍及使用总结

158 Bar _ Modèle Power bi utilise Dax + SVG pour créer des diagrammes d'affaires presque toutes les possibilités

正则表达式总结
![[elt.zip] openharmony paper Club - memory compression for data intensive applications](/img/54/8248c1d95b04498d44a00ea94a6c85.png)
[elt.zip] openharmony paper Club - memory compression for data intensive applications

07 local method stack

Command records of common data types for redis cli operations

Redis command string

158_模型_Power BI 使用 DAX + SVG 打通制作商业图表几乎所有可能

【深入理解TcaplusDB技术】单据受理之创建游戏区

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
随机推荐
LeetCode 322. Change exchange & dynamic planning
Current situation of China's hydraulic cylinder industry in 2020 (with application fields, policies and regulations, supply and demand status and enterprise pattern) [figure]
solidity获取季度时间
【深入理解TcaplusDB技术】单据受理之建表审批
Development status of China's hydrotalcite industry in 2020 and analysis of major enterprises: the market scale is rapidly increasing, and there is a large space for domestic substitution [figure]
Differences and relations between sequential table and array (easy to confuse), linear table and linked list
[compréhension approfondie de la technologie tcaplusdb] sauvegarde des données d'affaires tcaplusdb
焕新出发,利尔智达天下
华为发布两大昇腾计划 推动AI人才发展和科研创新
Lazy singleton mode from shallow to deep
Basic operations and basic data types of MySQL database
Redis configuration (Internet access, password)
Addition, deletion, modification and query of mysql~ tables (detailed and easy to understand)
RMAN backup database_ Duplexing backup sets
connect to address IP: No route to host
将Graph Explorer搬上JupyterLab:使用GES4Jupyter连接GES并进行图探索
初探Oracle全栈虚拟机---GraalVM
RMAN备份数据库_跳过脱机,只读和不可访问的文件
Pycharm 使用过程中碰到问题
Basic operation details of binary search tree (BST) (complete code, including test cases)