Vla_DOS

Завдання 2

Feb 20th, 2022
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleAppCSharp
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Write("Введите ширину массива: ");
  14.             int N = int.Parse(Console.ReadLine());
  15.             Console.Write("Введите длинну массива: ");
  16.             int M = int.Parse(Console.ReadLine());
  17.             //Console.Write("Введите диапазон массива: ");
  18.             //Console.Write("\n\tВведите минимальное число: ");
  19.             //int A = int.Parse(Console.ReadLine());
  20.             //Console.Write("\n\tВведите максимальное число: ");
  21.             //int B = int.Parse(Console.ReadLine());
  22.             Console.WriteLine();
  23.             int[,] arr = new int[M, N];
  24.  
  25.             Random a = new Random();
  26.  
  27.             for(int i = 0; i < arr.GetLength(0); i++)
  28.             {
  29.                 for(int j = 0; j < arr.GetLength(1); j++)
  30.                 {
  31.                     arr[i, j] = a.Next(-10, 10);
  32.                 }
  33.             }
  34.             for(int i = 0; i < arr.GetLength(0); i++)
  35.             {
  36.                 for(int j = 0; j < arr.GetLength(1); j++)
  37.                 {
  38.                     Console.Write("\t" + arr[i, j]);
  39.                 }
  40.                 Console.WriteLine();
  41.             }
  42.  
  43.             Console.Write("\n");
  44.  
  45.             int tmp;
  46.             int k=0;
  47.  
  48.             for(int j = 0; j < arr.GetLength(0) - 1; j++)
  49.             {
  50.                 for(int i = 0; i < arr.GetLength(1); i++)
  51.                 {
  52.                     if(j % 2 != 0)
  53.                     {
  54.                         k = 0;
  55.                         if(arr[i, j] < 0)
  56.                         {
  57.                             tmp = arr[k, j];
  58.                             arr[0+k, j] = arr[i, j];
  59.                             arr[0+i, j] = tmp;
  60.                             k++;
  61.                         }
  62.                     }
  63.                 }
  64.             }
  65.  
  66.             for(int i = 0; i < arr.GetLength(0); i++)
  67.             {
  68.                 for(int j = 0; j < arr.GetLength(1); j++)
  69.                 {
  70.                     Console.Write("\t" + arr[i, j]);
  71.                 }
  72.                 Console.WriteLine();
  73.             }
  74.         }
  75.     }
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment