# How do I print an n-line diamond in C #? Practical explanation

Source: Internet
Author: User

The idea of solving problems: First we print a diamond of n rows, the general diamond is odd line (look at a little), so we print out is an odd line of diamond, generally this form:

problem-solving ideas: We can think of the diamond as two parts, as the above a positive triangle and the following an anti-triangular composition, and then we can print out separately.

` Console.WriteLine ("Enter a positive integer greater than 2");//At least 3 rows to make a diamond, enter an even-numbered diamond is this even minus 1 lines int n = C Onvert.            ToInt32 (Console.ReadLine ()); for (int i = 1; I <= (n + 1)/2; i++)//print the upper portion of the diamond {for (int j = (n-1)/2; J >= i; j--                ) {//Print space Console.Write (""); } for (int k = 1; k <= i * 2-1; k++) {//print "*" number, line I have i*2-1 "*" Con Sole.                Write ("*");            } Console.WriteLine (); } for (int i = (n-1)/2; I >= 1; i--)//print Diamond The following section is the same as the above section {for (int j = i-1; J < (n-1)/2;                J + +) {Console.Write ("");                } for (int k = 1; k <= i * 2-1; k++) {Console.Write ("*");            } Console.WriteLine (); }`

If there is something wrong with the