当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
2. Creating Interactive Maps
深究equals
数组指针的使用方法
给我一个机会,帮你快速上手三子棋
求素数的三种方法
NAT种类及配置
前缀和相关:区域和检索 - 数组不可变、二维区域和检索 - 矩阵不可变...
js和jq实现点击小眼睛后密码显示与隐藏切换
2022华数杯建模C题思路解析
经典题型(一)
第二章:创建交互式地图(2.1-2.3)
3. Using Earth Engine Data
2022深圳杯D题思路:复杂水平井三维轨道设计
如何用栈实现队列
js实现滑动条验证
Mysql学习(二)
List,Set,Map,Queue,Deque,Stack遍历方式总结
Tracert 命令穿越防火墙不显示星号*的方法
同步锁synchronized追本溯源
字符菱形的代码









