SoFunction
Updated on 2025-03-01

The C# console program outputs isosceles triangle and centers the example


("Please enter the number of lines to be printed:");
            int n = Convert.ToInt32(());
(); //Clear the content displayed above
            string row = "";
//This layer of loop controls the number of lines printed
            for (int i = 1; i <= n; i++)
            {
//This layer of loop controls the number of * printed in front of each line
                for (int j = 1; j <= 2 * i - 1; j++)
                {
                    // ("*");
                    row += "*";
                }
//Every time after printing one line
//Set the printed * centered display
                (( - ) / 2, i);
                (row);
                row = "";
            }