
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print a 2 D Array or Matrix in C#
First, set a two-dimensional array.
int[,] arr = new int[10, 10];
Now, get the elements from the user −
for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { arr[i, j] = Convert.ToInt16(Console.ReadLine()); } }
Let us see the complete example to display the matrix.
Example
using System; using System.Linq; class Demo { static void Main() { int m, n, i, j; // rows and columns of the matrix+ m = 2; n = 2; int[,] arr = new int[10, 10]; Console.Write("Enter elements of the Matrix: "); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { arr[i, j] = Convert.ToInt16(Console.ReadLine()); } } Console.WriteLine("Printing Matrix: "); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { Console.Write(arr[i, j] + "\t"); } Console.WriteLine(); } Console.ReadLine(); } }
Output
The following is the output.
Enter elements of the Matrix: 5 10 12 15 Printing Matrix: 510 1215
- Related Questions & Answers
- Print a 2 D Array or Matrix in Java Programming
- Emulating a 2-d array using 1-d array in C++
- Print the corner elements and their sum in a 2-D matrix in C Program.
- Print a 2D Array or Matrix in Java
- Rotating a 2-D (transposing a matrix) in JavaScript
- Reshaping 2-D array in JavaScript
- Searching in a sorted 2-D array in JavaScript
- Finding transpose of a 2-D array JavaScript
- Build maximum array based on a 2-D array - JavaScript
- Stack 1-D arrays as columns into a 2-D array in Numpy
- Compute sum of all elements in 2 D array in C
- Sorting only columns of a 2-D array in JavaScript
- Grouping and sorting 2-D array in JavaScript
- Converting object to 2-D array in JavaScript
- Print 2-D co-ordinate points in ascending order followed by their frequencies in C++
Advertisements