Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp12
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)//Lukonkina
  8.         {
  9.             const int x = 7, y = 5;
  10.             int[,] a = new int[x, y];
  11.             int MaxIndexJ = 0; // номер в столбце
  12.             int MaxIndexI = 0; // номер в строке
  13.  
  14.             Random r = new Random();
  15.             for (int i = 0; i < x; i++)
  16.             {
  17.                 for (int j = 0; j < y; j++)
  18.                 {
  19.                     a[i, j] = r.Next(11);
  20.                 }
  21.             }
  22.             Console.WriteLine("Исходный массив");
  23.             for (int i = 0; i < x; i++)
  24.             {
  25.                 for (int j = 0; j < y; j++)
  26.                 {
  27.                     Console.Write("{0,4} ", a[i, j]);
  28.                 }
  29.                 Console.WriteLine();
  30.             }
  31.             Console.WriteLine();
  32.             int max = int.MinValue;
  33.             for (int i = 0; i < y; i++) // коор-та х
  34.             {
  35.                 max = int.MinValue;
  36.                 for (int j = 0; j < x; j++) // коор-та у
  37.                 {
  38.                     if (a[j, i] > max)
  39.                     {
  40.                         max = a[j, i];
  41.                         MaxIndexI = i;
  42.                         MaxIndexJ = j;
  43.                     }
  44.                 }
  45.                 Console.WriteLine("max = {0} ({1},{2})", max, MaxIndexJ, MaxIndexI);
  46.                 if (max < (a[i, 0] + a[i, y-1])/2)
  47.                 {
  48.                     a[MaxIndexJ, MaxIndexI] = (a[i, 0] + a[i, y-1]) / 2;
  49.                 }
  50.                 else
  51.                 {
  52.                     a[MaxIndexJ, MaxIndexI] = MaxIndexJ;
  53.                 }
  54.                 MaxIndexJ = 0;
  55.                 MaxIndexI = 0;
  56.             }
  57.             Console.WriteLine("\nИзмененный массив");
  58.             for (int i = 0; i < x; i++)
  59.             {
  60.                 for (int j = 0; j < y; j++)
  61.                 {
  62.                     Console.Write("{0,4} ", a[i,j]);
  63.                 }
  64.                 Console.WriteLine();
  65.             }
  66.             Console.Read();
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement