当前位置:网站首页>[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 !
边栏推荐
- Maximum continuous sub segment sum (dynamic programming, recursive, recursive)
- 1106 lowest price in supply chain (25 points)
- RT thread flow notes I startup, schedule, thread
- 1107 social clusters (30 points)
- [XSS bypass - protection strategy] understand the protection strategy and better bypass
- The consumption of Internet of things users is only 76 cents, and the price has become the biggest obstacle to the promotion of 5g industrial interconnection
- Caijing 365 stock internal reference: what's the mystery behind the good father-in-law paying back 50 million?
- [set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)
- Current market situation and development prospect prediction of global direct energy deposition 3D printer industry in 2022
- [research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
猜你喜欢
String matching: find a substring in a string
SSM framework integration
Basic use of Metasploit penetration testing framework
Gbase8s unique index and non unique index
Retirement plan fails, 64 year old programmer starts work again
Analysis of proxy usage of ES6 new feature
Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution
leetcode860. Lemonade change
MPM model and ab pressure test
Burp suite plug-in based on actual combat uses tips
随机推荐
How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in
RT thread flow notes I startup, schedule, thread
Shell script -- condition judgment
Market status and development prospect prediction of the global fire alarm sensor industry in 2022
112 stucked keyboard (20 points)
On typescript and grammar
document. The problem of missing parameters of referer is solved
Market status and development prospects of the global automatic tea picker industry in 2022
Wechat applet waterfall flow and pull up to the bottom
[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)
Problems encountered in fuzzy query of SQL statements
Shell script Basics - basic grammar knowledge
The process of browser accessing the website
论文阅读_清华ERNIE
MPM model and ab pressure test
Notes | numpy-09 Broadcast
Dynamic programming - related concepts, (tower problem)
leetcode452. Detonate the balloon with the minimum number of arrows
[backtrader source code analysis 5] rewrite several time number conversion functions in utils with Python
Realize file download through the tag of < a > and customize the file name