Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OnlineExercise15._4
- {
- class Program
- {
- static Random randomGenerator = new Random();
- static void GenerateMatrix(int[,] matrix)
- {
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int j = 0; j < matrix.GetLength(1); j++)
- {
- matrix[i, j] = randomGenerator.Next(-100, 100);
- }
- }
- }
- static void PrintMatrix(int[,] matrix)
- {
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int j = 0; j < matrix.GetLength(1); j++)
- {
- Console.Write(matrix[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- static int[,] Transpose(int[,] matrix)
- {
- int w = matrix.GetLength(0);
- int h = matrix.GetLength(1);
- int[,] result = new int[h,w];
- for(int i = 0; i < w; i++)
- {
- for(int j = 0; j < h; j++)
- {
- result[j, i] = matrix[i, j];
- }
- }
- return result;
- }
- static void PrintTransposed(int[,] matrix)
- {
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int j = 0; j < matrix.GetLength(1); j++)
- {
- Console.Write(matrix[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- int[,] matrix = new int[5, 4];
- GenerateMatrix(matrix);
- PrintMatrix(matrix);
- Console.WriteLine();
- Console.WriteLine();
- PrintTransposed(Transpose(matrix));
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment