Print a triangular pattern of asterisks

后端 未结 15 1035
慢半拍i
慢半拍i 2020-11-30 11:01

I am required to use nested for loops and print(\'*\', end=\' \') to create the pattern shown here:

And here is my code. I have figured out the first t

15条回答
  •  一向
    一向 (楼主)
    2020-11-30 11:28

    var n = 5;
    
        for(int row = 0 ; row < n; row++)
        {
            for(int col = 1; col <= n; col++)
            {
                if(col < n - row)
                {
                    Console.Write(" ");
                }
                else
                {
                    Console.Write("*");
                }
    
            }
            Console.WriteLine();
    
        }
    

    (D)

提交回复
热议问题