In this example, I will create a program that allows the user to enter numbers by creating a 3×3 matrix in the C # programming language.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | static void Main(string[] args) { const int MATRIX_ROWS = 3; const int MATRIX_COLUMNS = 3; double[,] matrix = new double[MATRIX_ROWS, MATRIX_COLUMNS]; for (int i = 0; i < MATRIX_ROWS; i++) { for (int j = 0; j < MATRIX_COLUMNS; j++) { Console.Write("Enter value for ({0},{1}): ", i, j); matrix[i, j] = double.Parse(Console.ReadLine()); } } Console.WriteLine(); for (int i = 0; i < MATRIX_ROWS; i++) { for (int j = 0; j < MATRIX_COLUMNS; j++) { Console.Write(matrix[i,j] + "\t"); } Console.WriteLine(); } Console.ReadKey(); } |
Output: