Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Week2MatrixRotation
- {
- static void Main()
- {
- int n = 3;
- int[,] matrix = new int[n, n];
- /* The counter will be filling the matrices, as the numbers in them are to be consecutive */
- int counter;
- // filling the matrix
- counter = 1;
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < n; col++)
- {
- matrix[col, row] = counter;
- counter++;
- }
- }
- // 1st print
- for (int rows = 0; rows < n; rows++)
- {
- for (int cols = 0; cols < n; cols++)
- {
- // changed places of rows and columns, so that we can get the columns printed one by one
- Console.Write("{0,3}", matrix[cols, rows]);
- }
- Console.WriteLine();
- }
- Console.WriteLine();
- // 2rd print: 1st 90% rotation
- for (int rows = 0; rows < n; rows++)
- {
- for (int cols = n - 1; cols >= 0; cols--)
- {
- Console.Write("{0,3}", matrix[rows, cols]);
- }
- Console.WriteLine();
- }
- Console.WriteLine();
- // 3rd print: 2nd 90% rotation
- for (int rows = n - 1; rows >= 0; rows--)
- {
- for (int cols = n - 1; cols >= 0; cols--)
- {
- Console.Write("{0,3}", matrix[cols, rows]);
- }
- Console.WriteLine();
- }
- Console.WriteLine();
- // 4th print: 3rd 90% rotation
- for (int rows = n - 1; rows >= 0; rows--)
- {
- for (int cols = 0; cols < n; cols++)
- {
- Console.Write("{0,3}", matrix[rows, cols]);
- }
- Console.WriteLine();
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement