Hi guys, i'm new to C#. I have been trying to create a matrix or size 3x3 with the following code:
using System;
class matrix
{
static void Main(string[] args)
{
Console.Write("Enter values for the matrix: ");
int [,]matrx=new int[3,3];
for(int i=0;i<3;i++)
{
for (int j = 0; j < 3; j++)
{
matrx[i, j] = Console.Read();
}
}
for(int i=0;i<3;i++)
{
for (int j = 0; j < 3; j++)
{
Console.Write(" " +matrx[i, j]);
}
Console.WriteLine();
}
}
}
The problem is that it accepts only 3(should be 9) values but gives an output of complete 3x3 matrix with random values. For eg. if i entered the first three numbers (elements) as 1,2 & 3 (after which the loop exits itself n goes to the output), it gives the following output:
Enter values for the matrix: 1
2
3
49 13 10
50 13 10
51 13 10
Press any key to continue...
It is my belief that the problem is with the Console.Read() line. However, i would be really grateful if you guys point out as to why i'm not getting the desired result. Thanking you all in advance.