Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class PrintMatrix
- {
- static void Main()
- {
- string[] separators = { " ", "\t" };
- Console.WriteLine("Enter N (width/height of the matrix): ");
- int n = int.Parse(Console.ReadLine());
- int[,] matrix = new int[n, n];
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- Console.WriteLine("Enter all {0} values on row number {1} separated by space:", n, (row + 1));
- string currentLine = Console.ReadLine();
- string[] numbersOnLine = currentLine.Split(separators, StringSplitOptions.RemoveEmptyEntries);
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- if (col < numbersOnLine.Length)
- {
- matrix[row, col] = int.Parse(numbersOnLine[col]);
- }
- }
- }
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- Console.Write("{0}".PadRight(15 - matrix[row,col].ToString().Length), matrix[row, col]);
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement