using System.Collections.Generic;
public static void Main() {
Console.Write("Rows Count: ");
rows = int.Parse(Console.ReadLine());
Console.Write("Columns Count: ");
cols = int.Parse(Console.ReadLine());
int [,] matrix = new int[rows, cols];
for(int r = 0; r < rows; r++) {
for(int c = 0; c < cols; c++) {
Console.Write("Element {0} x {1}: ", r, c);
matrix[r, c] = int.Parse(Console.ReadLine());
Console.WriteLine("\nOriginal Matrix");
Console.WriteLine("\nTransposed Matrix");
PrintMatrix(Transpose(matrix));
public static int[,] Transpose(int[,] matrix) {
int rows = matrix.GetUpperBound(0) + 1;
int cols = matrix.GetUpperBound(1) + 1;
int[,] transposed = new int[cols, rows];
for(int r = 0; r < rows; r++) {
for(int c = 0; c < cols; c++) {
transposed[c,r] = matrix[r,c];
public static void PrintMatrix(int [,] matrix) {
int rows = matrix.GetUpperBound(0) + 1;
int cols = matrix.GetUpperBound(1) + 1;
for(int r = 0; r < rows; r++) {
for(int c = 0; c < cols; c++) {
Console.Write("{0,5} ", matrix[r,c]);