Fortune Telling Collection - Free divination - Star permutation algorithm (C++ or C language)
Star permutation algorithm (C++ or C language)
* * Consider the graph as two symmetrical parts.
* * Both parts are 4 lines, but in the opposite order.
* * So write a two-level loop statement.
* * As long as I is reduced and increased respectively, the graphs of these two parts can be obtained.
* * There is a problem. Hi, I ... ...
*/
# include & ltiostream & gt
Use namespace std
int main()
{
int i,j,k;
//The first part of the graph starts with i=4 and decreases to 1.
for(I = 4; I>= 1; I-)// The number of rows in the first-level loop control.
{
j = I * 2- 1;
k = j/2;
While((3-k)>0) // Controls the number of spaces in the output.
{
cout & lt& lt" ";
k++;
}
while(j & gt; 0) // Controls the number of times the symbol "*" is output.
{
cout & lt& lt"*";
j-;
}
cout & lt& lt\ n '; //The end of a line of output
}
//The second part of the diagram starts from i= 1 and increases to 4.
for(I = 1; I < = 4; i++)
{
j = I * 2- 1;
k = j/2;
while((3-k)>0)
{
cout & lt& lt" ";
k++;
}
while(j & gt; 0)
{
cout & lt& lt"*";
j-;
}
cout & lt& lt\ n ';
}
Returns 0;
}
- Related articles
- What did it mean when you were born?
- Fate characteristics of past lives
- What kind of experience is it to have a girlfriend who is good at lying?
- Look at the list of gods again to solve the problem!
- Four-character idioms in grades one to three
- I don't regret it. How did Samsung get through the customs in the battle of Changping, China?
- Dongba detailed data collection
- I went to draw tarot cards today, asking for an explanation.
- Do lion women and Aquarius men, Aquarius men and Leo women match?
- Aries 2020 love career fortune zodiac horoscope detailed explanation.