[C#] While Loop สามเหลี่ยม

โค้ด

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonRandom_Click(object sender, EventArgs e)
        {
            Random rdObj = new Random();
            int num = rdObj.Next(10);
            textBox1.Text = "";

            int row = 1;
            int col = 1;

            while (row <= num)
            {
                while (col <= row)
                {
                    textBox1.Text += num.ToString() + " ";
                    col++;
                }
                textBox1.Text += "\r\n";
                row++;
                col = 1;
            }
            
        }
    }
}
Previous
Next Post »