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 ConsoleApplication7
- {
- class Program
- {
- static void Main(string[] args)
- {
- int size = int.Parse(Console.ReadLine());
- int[,] matrix = new int[size, size];
- int rows = matrix.GetLength(1);
- int cols = matrix.GetLength(0);
- int counterOutput = 1;
- for (int i = 0; i < rows; i++)
- {
- if (i % 2 == 0)
- {
- for (int j = 0; j < cols; j++)
- {
- matrix[j , i] = counterOutput;
- counterOutput++;
- }
- }
- else
- {
- for (int j = cols - 1; j >= 0; j--)
- {
- matrix[j, i] = counterOutput;
- counterOutput++;
- }
- }
- }
- Console.WriteLine("The matrix is as follows:");
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- Console.Write("{0} ", matrix[row, col]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment