当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
学编程的第八天
认识盒子模型
字符菱形的代码
看得见风和日丽,看不见风起“云”涌
ARM基础知识点笔记
MySQL必知必会(一)
Win10 安装系统跳过创建用户,直接启用 administrator
2022华数杯建模C题思路解析
RAID磁盘阵列详解
Mysql(四)
C语言基本数据类型的存储大小、取值范围、输出格式的解剖
Go语言基础(十):接口
动态规划相关:三角形最小路径和
新电脑自带win11,开机怎样跳过连网
前言:关于作者吴秋生博士与此书简介
标准IO及其各函数用法
基于FTP协议的文件上传与下载
js和jq实现点击小眼睛后密码显示与隐藏切换
在追梦的路上,唯独脚踏实地,才能梦想成真
安装MySQL时出现starting the server失败