当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Heap series_0x06: NT global flags and gflags.exe one page
Zip包的读取与写入
2022华数杯建模C题思路解析
微信小程序学习记录(一)
0. About The Author And Preface
js中的Date对象 及 将时间戳转换为yy-mm-dd hh:mm:ss格式的方法
Ntdsutil 清除无效的辅域控制器DC
经典题型(一)
while read line中执行ssh出现只执行一次
用指针和malloc定义一个数组
继承关系下构造方法的访问特点
单臂路由与三层交换机实现跨VLAN通讯
Dolphin Scheduler 2.x版本部署篇
2022年深圳杯建模A题思路: 破除“尖叫效应”与“回声室效应”,走出“信息茧房”
初识C语言,了解一下C语言轮廓
九章云极DataCanvas APS机器学习平台获得中国信通院“领先级”评级
传输层协议TCP/UDP
0. About The Author And Preface
properties文件的读取和写入
文字样式的常见属性的如何使用?