The C console program outputs isosceles triangles and displays the instance centered
- 2021-01-19 22:21:23
- OfStack
Just help a friend of the most 1 exercise problem, the request uses the console output 1 isosceles of 3 Angle shape, and want to center display. Output isosceles 3 Angle is relatively simple, there are a lot of online, but the need to do the output of the center display will not be some, finally hard work pays off, finally is made, the specific content is as follows, very simple and clear, the code content is as follows:
Console.WriteLine(" Please enter the number of lines to print: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.Clear(); // Clear the content shown above
string row = "";
// This loop controls the number of lines printed
for (int i = 1; i <= n; i++)
{
// This layer of loops controls each line before printing * The number of
for (int j = 1; j <= 2 * i - 1; j++)
{
// Console.Write("*");
row += "*";
}
// After each print 1 Line in 1 The downside
// Set it to print out * centered
Console.SetCursorPosition((Console.WindowWidth - row.Length) / 2, i);
Console.WriteLine(row);
row = "";
}