当前位置:网站首页>C语言打印菱形
C语言打印菱形
2022-07-27 16:25:00 【许烦】
思路:简单明了的说一下,首先我们可以将菱形分成上半部分和下半部分,用3个for循环打印上半部分,再用3个for循环打印下半部分,至于for循环里面的判断条件为什么要这样写,你记住就行了,不要问为什么,你问的话,它逻辑就是通的。。。。。
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main() {
int i, j, k;
for (i = 0; i <= 3; i++) { //控制上半部分的行数
for (j = 0; j <= 2 - i; j++) {
printf(" "); //利用行数对应关系打印空格
}
for (k = 0; k <= 2*i; k++) {
printf("*"); //利用行数对应关系打印星号
}
printf("\n");
}
for (i = 0; i <= 2; i++) { //控制下半部分行数
for (j = 0; j <= i; j++) {
printf(" "); 利用行数对应关系打印空格
}
for (k = 0; k <= 4 - 2 * i; k++) {
printf("*"); //利用行数对应关系打印星号
}
printf("\n");
}
return 0;
}边栏推荐
- Useful resources for ns2
- Unity learning notes (rigid body physics collider trigger)
- I'm afraid I won't use the JMeter interface testing tool if I accept this practical case
- WSN journal indexed by SCI
- Word 2007+ tips
- Greedy method, matroid and submodular function (refer)
- Redis annotation
- [wechat applet] project practice - lottery application
- 【云图说】 第250期 初识华为云微服务引擎CSE
- Low noise anion fan touch IC
猜你喜欢
随机推荐
WSN Journal indexed by SCI(转)
Extension of regular expression
Ruiji takeout SQL table
连续时间系统的性能分析(1)-控制系统性能指标及一二阶分析
Useful resources for ns2
Intelligent insomnia therapeutic instrument product dlt8p68sa Jericho
Nodejs template engine EJS
【微信小程序】项目实战—抽签应用
Usage of ref keyword
【云图说】 第250期 初识华为云微服务引擎CSE
NPM basic use
Nacos的基本使用(1)——入门
Sentinel1.8.4 persistent Nacos configuration
自控原理学习笔记-系统稳定性分析(2)-环路分析及Nyquist-Bode判据
专项测试之「 性能测试」总结
Nodejs 模板引擎ejs
MySQL 01 relational database design
The understanding of string in C.
JDBC MySQL 01 JDBC operation MySQL (add, delete, modify and query)
Introduction to assembly language (1)









