Use a while loop to input multiple values from the user in one line.
Let’s say you need to get the elements of a matrix. Get it using Console.ReadLine() as shown below −
Console.Write("\nEnter elements - Matrix 1 : "); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { arr1[i, j] = Convert.ToInt16(Console.ReadLine()); } }
The following is an example showing how we can input multiple values from user −
using System; namespace Demo { public class Program { public static void Main(string[] args) { int[,] arr1 = new int[10, 10]; int i, j; Console.Write("\nEnter Matrix elements: "); for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { arr1[i, j] = Convert.ToInt16(Console.ReadLine()); } } } } }
Enter Matrix elements: