Advertisement
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;
- class MatrixRotation
- {
- static void Main(string[] args)
- {
- int size = int.Parse(Console.ReadLine());
- int index = 1;
- int[,] matrix = new int[size, size];
- for (int i = 0; i < size * size; i++)
- {
- matrix[i / size, i % size] = index++;
- }
- matrix = Rotate(matrix);
- Print(matrix);
- }
- static int[,] Rotate(int[,] input)
- {
- int len = input.GetLength(0);
- int[,] output = new int[len, len];
- for (int i = 0; i < len; i++)
- {
- for (int j = len - 1; j >= 0; j--)
- {
- output[i, len - j - 1] = input[j, i];
- }
- }
- return output;
- }
- static void Print(int[,] matr)
- {
- for (int i = 0; i < matr.GetLength(0); i++)
- {
- for (int j = 0; j < matr.GetLength(1); j++)
- {
- Console.Write(matr[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement