pt.so/220469

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		int [,] array = new int[10, 10] 
		{ 
			{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 
			{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 
			{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 
			{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 
			{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 
			{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 
			{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 
			{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 
			{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
			{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } 
		};
		
		var novaMatriz = Transpor(array);
		
		for(int i = 0; i < novaMatriz.GetLength(0); i++) 
		{
			for(int c = 0; c < novaMatriz.GetLength(1); c++)
			{
				Console.Write(novaMatriz[i, c] + "|");
			}
			
			Console.WriteLine("");
		}
	}
	
	public static int[,] Transpor(int[,] matriz)
	{
		int w = matriz.GetLength(0);
		int h = matriz.GetLength(1);
	
		int[,] novaMatriz = new int[h, w];
	
		for (int i = 0; i < w; i++)
		{
			for (int j = 0; j < h; j++)
			{
				novaMatriz[j, i] = matriz[i, j];
			}
		}
	
		return novaMatriz;
	}
}
;