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;
- namespace ConsoleApplication14
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Введите n > 0");
- int n = GetNumber();
- Console.WriteLine("Введите длину столбца");
- int row = GetNumber();
- int col = (n / row) + 1;
- int[,] array = new int[row, col];
- int i = 0, j = 0, temp = 1;
- while (i < col)
- {
- while (j < row)
- {
- if (temp <= n)
- array[j,i] = temp;
- else array[j, i] = -1;
- temp++;
- j++;
- }
- i++;
- j--;
- if (i >= col)
- break;
- while (j >= 0)
- {
- if (temp <= n)
- array[j, i] = temp;
- else array[j, i] = -1;
- temp++;
- j--;
- }
- i++;
- j++;
- }
- for (int f = 0; f < row; f++)
- {
- Console.WriteLine();
- for (int k = 0; k < col; k++)
- Console.Write(array[f, k] + " ");
- }
- Console.Read();
- }
- private static int GetNumber()
- {
- string data = Console.ReadLine();
- int f = 0;
- while (true)
- {
- if (Int32.TryParse(data, out f))
- if (Int32.Parse(data) > 0)
- break;
- else Console.WriteLine("Введите число больше 0");
- else Console.WriteLine("Введите число");
- data = Console.ReadLine();
- }
- return Int32.Parse(data);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement