当前位置:网站首页>character rhombus code
character rhombus code
2022-08-09 17:48:00 【I'm free*】
//Print a rhombus
//Take it as a patchwork of two triangular rows, a triangular row + remove the inversion of the lowest row of this triangular row
// First find the total number of rows n1 of the upper triangular row=(row/2+1) row is the total number of rows of diamonds
// The output logic of the upper triangle
// The number of * follows the law: n1 is the total number of rows in the upper triangle i is the first row i is initialized to 1 i--=>n1 *Number: 2*i-1
// The number of spaces follows the law: n1 is the total number of lines in the upper triangle i is the number of lines i is initialized to 1 i--=>n1 The number of spaces: n1-i
//The output logic of the lower triangle (remove the inversion of the lowest row of this triangle row)
//The total number of rows in the lower triangle row n2=row/2 The row is the total number of rows in the diamond shape
//The lower triangle rowOutput logic
//The law of the number of * follows the line: n2 is the total number of lines in the lower triangle i is initialized to num/2 i--=>0 The number of *: 2*i-1
//The number of spaces follows the lineThe law: n2 is the total number of rows in the lower triangle i is initialized to num/2 i--=>0 The number of spaces: n1-i
//Print diamond// Think of it as a patchwork of two triangular rows, a triangular row + the inversion of the lowest row that removes this triangular row// First find the total number of rows in the upper triangle row n1=(row/2+1) row is the total number of rows of diamonds// Output logic for upper triangle// The number of * follows the law: n1 is the total number of rows in the upper triangle i is the number of rows i is initialized to 1 i--=>n1 The number of *: 2*i-1// The number of spaces follows the law: n1 is the total number of lines in the upper triangle i is the number of lines i is initialized to 1 i--=>n1 Number of spaces: n1-i//The output logic of the lower triangle (remove the inversion of the lowest row of this triangle row)//The total number of rows in the lower triangle row n2=row/2 row is the total number of rows in the diamond//Lower triangle line output logic//* The number of rows follows the law: n2 is the total number of rows in the lower triangle i is initialized to num/2 i--=>0 *Number: 2*i-1//The number of spaces follows the law: n2 is the total number of lines in the lower triangle i is initialized to num/2 i--=>0 The number of spaces: n1-i#include int main(){char s = '\0';int row = 0; //total number of rowsscanf("%c %d", &s, &row); //input characters and total number of linesint i = 0, black = 0, k = 0; //black is a space variable nameint n1 = row / 2 + 1; //The number of rows in the upper triangleint n2 = row / 2; //Number of rows in the lower triangle//Print out the upper triangle line graphicsfor (i = 1;i <=n1;i++){for (black = 1;black <= n1 - i;black++){printf(" ");}k = 1;while (k <= 2 * i - 1){printf("*");k++;}printf("\n");}// print out the lower triangle shapefor (i = n2;i >= 0;i--){for (black = 1;black <= n1 - i;black++){printf(" ");}k = 1;while (k <= 2 * i - 1){printf("*");k++;}printf("\n");}return 0;}
Be sure to add appropriate comments when writing code, which is not only conducive to others' viewing, but also to your own later inspection.
The test environment for this code is CodeBlocks, I hope this article is helpful to you
边栏推荐
猜你喜欢
随机推荐
后代选择器和子代选择器
vs2017下配置sqlite3环境
学编程的第十天
2022华数杯建模A题思路解析
前缀和相关:区域和检索 - 数组不可变、二维区域和检索 - 矩阵不可变...
Go语言基础(十):接口
微信小程序学习(二)
字典树、并查集相关:实现Trie、搜索推荐系统、朋友圈、被围绕的区域(未做) ...
第三章:GEE数据的使用(3.4-3.11)
Tracert 命令穿越防火墙不显示星号*的方法
经典题型(一)
学习编程的第四天
2022华数杯建模B题思路解析
Go语言基础(十二):并发编程
QT页面跳转的实现
为什么四个字节的float表示的范围比八个字节的long要广
Anatomy of Storage Size, Value Range, and Output Format of Basic Data Types in C Language
Lens 创建 Service Accounts 及分配权限
C语言知识细节点(二)
传输层协议TCP/UDP









