当前位置:网站首页>C language printing diamond
C language printing diamond
2022-06-11 08:55:00 【Jimmy_ jimi】
The goal is : Print diamond

analysis :
It is not difficult to find out the rules by labeling each row and column , Per row per column ’*' No. 1 is empty , It can be judged that 2 Modular calculation . To exclude the upper left and lower right patterns, you need to control the sum of both , Similarly, control the difference between the two to eliminate the other two extra corners .
Result output :
#include <stdio.h>
#include <stdlib.h>
int main() {
for (int j = 1; j < 10; j++)
{
for (int i = 0; i < 10; i++)
{
if (i+j>=6 && i+j <=14 && (i+j)%2==0 && i-j<6 && i-j>-6 )
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
}
Similarly, analyze the hollow diamond
#include <stdio.h>
#include <stdlib.h>
int main() {
for (int j = 1; j < 10; j++)
{
for (int i = 1; i < 10; i++)
{
if (i + j == 6 || i + j == 14 || j-i==4 || i-j==4 )
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
}
边栏推荐
- Screaming Frog Log File Analyser 中文版安装教程
- What software is required to process raw format images?
- Sword finger offer 10- ii Frog jumping on steps
- EN 45545-2:2020 T11烟毒性检测
- SAP material master data archiving
- MySQL & Oracle database capacity query
- GCC AVR(Atmel Studio+ AVR Studio)如何将结构体数组定义在程序存储器(flash)空间并进行读操作
- What if the copied code format is confused?
- 标准化编写知识
- 端口占用问题,10000端口
猜你喜欢
随机推荐
PHP uploading large files for more than 40 seconds server 500
Can not connect to local MySQL server through socket ‘/tmp/mysql. sock (2)‘
Codeworks round 723 (Div. 2)
MySQL死锁问题如何解决?背诵版
String类为何final修饰
What are precompiled, compiled, assembled, linked, static and dynamic libraries
EN 45545-2:2020 T11 smoke toxicity test
Matlab learning 8- linear and nonlinear sharpening filtering and nonlinear smoothing filtering of image processing
leetcode - 460. LFU cache
Analysis of EN 45545 R24 oxygen index test method
ActiveMQ简单教程,适合初学者,学习笔记yyds
Sword finger offer 10- ii Frog jumping on steps
Hibernate L2 cache
MySQL advanced features, you can read more about it and meet the interview
木板ISO 5660-1 热量释放速率摸底测试
MySQL upgrade
Matlab学习9-图像处理之非线性锐化滤波
【Image Processing】空间域图像增强
GCC AVR (ATMEL studio+ AVR studio) how to define the structure array in the program memory (flash) space and read it
Codetop - sort odd ascending even descending linked list









