PROGRAMMING:Output diamond pattern
The user inputs a positive integer n (1 < = n < = 10) and a character a, and outputs a diamond pattern composed of a, with a total of 2N-1 lines.
###Input format:
There is no space between a positive integer n (1 < = n < = 10) and a character a.
###Output format:
A diamond pattern composed of a character, 2N-1 lines in total.
###Input example:
```in
3$
```
###Output example:
```out
$
$$$
$$$$$
$$$
$
```
answer:If there is no answer, please comment
This is a double loop problem, outer loop is row, inner loop is column.
As long as it is a graphic printing topic, it can be resolved as "how many lines should I type? Each line is composed of several spaces, several characters and a carriage return character.
This is a diamond. The characteristic of the diamond is that the upper triangle is increasing and the lower triangle is decreasing. Increasing and decreasing are two different rules, so we need to print two triangles separately.
Let's take a look at the triangle above. Let's put the long line into the upper triangle. Assuming that the user inputs n, it means that we want to print n lines. The outer loop variable I loops from 1 to n. For each line I, you need to type a number of spaces, a number of characters, and a carriage return. We can try to find the rules:
Suppose n = 3
When I = 1, the number of spaces is 2 and the number of characters is 1
When I = 2, the number of spaces is 1 and the number of characters is 3
When I = 3, the number of spaces is 0 and the number of characters is 5
OK, we substitute n into the regular formula. We can find that the number of spaces is n-i and the number of characters is 2i-1. Well, for each I, there are two inner loops. One inner loop is to print spaces, and the number of cycles is n-i. one inner loop is to print characters, and the number of cycles is 2i-1. After printing spaces and characters, add a carriage return.
Now, let's find out the law of the triangle.
###Input format:
There is no space between a positive integer n (1 < = n < = 10) and a character a.
###Output format:
A diamond pattern composed of a character, 2N-1 lines in total.
###Input example:
```in
3$
```
###Output example:
```out
$
$$$
$$$$$
$$$
$
```
answer:If there is no answer, please comment
This is a double loop problem, outer loop is row, inner loop is column.
As long as it is a graphic printing topic, it can be resolved as "how many lines should I type? Each line is composed of several spaces, several characters and a carriage return character.
This is a diamond. The characteristic of the diamond is that the upper triangle is increasing and the lower triangle is decreasing. Increasing and decreasing are two different rules, so we need to print two triangles separately.
Let's take a look at the triangle above. Let's put the long line into the upper triangle. Assuming that the user inputs n, it means that we want to print n lines. The outer loop variable I loops from 1 to n. For each line I, you need to type a number of spaces, a number of characters, and a carriage return. We can try to find the rules:
Suppose n = 3
When I = 1, the number of spaces is 2 and the number of characters is 1
When I = 2, the number of spaces is 1 and the number of characters is 3
When I = 3, the number of spaces is 0 and the number of characters is 5
OK, we substitute n into the regular formula. We can find that the number of spaces is n-i and the number of characters is 2i-1. Well, for each I, there are two inner loops. One inner loop is to print spaces, and the number of cycles is n-i. one inner loop is to print characters, and the number of cycles is 2i-1. After printing spaces and characters, add a carriage return.
Now, let's find out the law of the triangle.