6
Reply

2d array with random number

Jonathan Crispe

Jonathan Crispe

Nov 8 2011 9:24 PM
4.1k
i had programming exam this morning...i failed...
still i wanna know how to do this.
instruction:
create 2d array [5,5] with random number from 0 to 9... and calculate the column...

        private void button1_Click(object sender, EventArgs e)
        {
            int[,] iArray = new int[5, 5];
            Random rnumber = new Random();
            int inum = rnumber.Next(0, 9);

            for (int x = 0; x < iArray.GetLength(0); x++)
            {
                for (int y = 0; y < iArray.GetLength(1); y++)
                {
                    iArray[x, y] = inum;
                    label1.Text = inum.ToString();
                }
            }
        }
my code showing only 1 random number. instead of 5 by 5 random number...


Answers (6)