当前位置:网站首页>[basic grammar] C language uses for loop to print Pentagram
[basic grammar] C language uses for loop to print Pentagram
2022-07-03 05:05:00 【The beginning of Hongmeng】
This time, we provide you with a C Language print Pentagram code
Catalog
One 、 Realization effect
Print the five pointed star as shown in the figure
First, build a two-dimensional array , Divide the five pointed star into four parts from top to bottom , Use different for The loop statement fills a two-dimensional array * To build the completed Pentagram
Two 、 Complete code
#include <stdio.h>
char wj[15][38];
int main()
{
int i=0, j=0, k, m4, n4;
for (int i = 0; i < 5; i++) // This is the upper corner of the pentagram (4 That's ok )
{
for (int j = 0; j < 18 - i; j++)// Find rules and read spaces in the array
wj[i][j] = ' ';
for (j = 18-i; j <= i + 18; j++)// Find rules and read them in the array *
wj[i][j] = '*';
}
for (i = 5; i < 9; i++) // These are the middle two corners of the pentagram (4 That's ok )
{
for (j = 0; j < 3 * i - 15; j++)
wj[i][j] = ' ';
for (j = 3 * i - 15; j <= 51 - 3 * i; j++)
wj[i][j] = '*';
}
for (i = 9; i < 11; i++) // This is the part where the middle meets the lower part (2 That's ok )
{
for (j = 0; j < 20 - i; j++)
wj[i][j] = ' ';
for (j = 20 - i; j <= 15 + i; j++)
wj[i][j] = '*';
}
for (i = 11; i < 15; i++) // These are the lower two corners of the pentagram (4 That's ok )
{
for (j = 0; j < 20 - i; j++)
wj[i][j] = ' ';
for (j = 20 - i; j <= 49 - 3 * i; j++)
wj[i][j] = '*';
for (j = 50 - 3 * i; j < 3 * i - 14; j++)// The space between the lower two corners
wj[i][j] = ' ';
for (j = 3 * i - 14; j < i + 16; j++)
wj[i][j] = '*';
}
for (i = 0; i < 15; i++)// Loop out the entire two-dimensional character array
{
for (j = 0; j < 38; j++)
printf("%c", wj[i][j]);
printf("\n");
}
}
That's all this time , Thank you for taking the time to read my book , Please correct . Welcome to discuss and share your questions or experiences in the comment area , I hope this article can help you , I wish you a happy life !
边栏推荐
- 1118 birds in forest (25 points)
- [XSS bypass - protection strategy] understand the protection strategy and better bypass
- Gbase8s unique index and non unique index
- JDBC database operation
- Flutter monitors volume to realize waveform visualization of audio
- Market status and development prospect prediction of global fermented plant protein industry in 2022
- 最大连续子段和(动态规划,递归,递推)
- leetcode452. Detonate the balloon with the minimum number of arrows
- 1110 complete binary tree (25 points)
- [set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
猜你喜欢
[tools run SQL blind note]
Mobile terminal - uniapp development record (public request encapsulation)
Shuttle + alluxio accelerated memory shuffle take-off
Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
论文阅读_ICD编码_MSMN
Preparation for school and professional cognition
Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)
Handler understands the record
[research materials] annual report of China's pension market in 2021 - Download attached
Actual combat 8051 drives 8-bit nixie tube
随机推荐
SSM framework integration
音频焦点系列:手写一个demo理解音频焦点与AudioMananger
Retirement plan fails, 64 year old programmer starts work again
[set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)
Actual combat 8051 drives 8-bit nixie tube
Chapter II program design of circular structure
Market status and development prospect prediction of the global forward fluorescent microscope industry in 2022
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
Market status and development prospects of the global automatic tea picker industry in 2022
5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
[backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times
Thesis reading_ ICD code_ MSMN
Gbase8s unique index and non unique index
appium1.22.x 版本後的 appium inspector 需單獨安裝
Review the old and know the new: Notes on Data Science
Sprintf formatter abnormal exit problem
My first Smartphone
Unity tool Luban learning notes 1
Flutter monitors volume to realize waveform visualization of audio
[PHP vulnerability weak type] basic knowledge, PHP weak equality, error reporting and bypassing