Advertisement
MrVeiran

задача 4

Mar 11th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.90 KB | None | 0 0
  1. задача с выводом максимума
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp22
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int x, y, max, gr;
  15.             int[,] ar = new int[10, 10];
  16.             int[] kol1 = new int[100];
  17.             int[] kol2 = new int[100];
  18.             int[] kol3 = new int[100];
  19.             for (int i = 0; i < 10; i++)
  20.             {
  21.                 for (int j = 0; j < 10; j++)
  22.                 {
  23.                     Random rnd = new Random();
  24.                     int rek = rnd.Next(100);
  25.                     ar[i, j] = rek;
  26.  
  27.  
  28.                 }
  29.                 //я хз, но почему то в режиме отладки выводится
  30.                 //всегда одно и тоже число, а в пошаговом всёо тлично
  31.             }
  32.             Console.WriteLine("Первый массив");
  33.             for (int i = 0; i < 10; i++)
  34.             {
  35.                 for (int j = 0; j < 10; j++)
  36.                 {
  37.                     Console.Write(ar[i, j]);
  38.                     if (ar[i, j] < 10)
  39.                     {
  40.                         Console.Write(' ');
  41.                     }
  42.                     Console.Write('|');
  43.  
  44.  
  45.                 }
  46.                 Console.WriteLine();
  47.             }
  48.  
  49.             max = ar[0, 0];
  50.             y = 0;
  51.             x = 0;
  52.             Console.WriteLine();
  53.             Console.WriteLine("Второй массив");
  54.             for (int i = 0; i < 10; i++)
  55.             {
  56.                 for (int j = 0; j < 10; j++)
  57.                 {
  58.                     if (max < ar[i, j])
  59.                     {
  60.                         max = ar[i, j];
  61.                         x = j;
  62.                         y = i;
  63.                     }
  64.                 }
  65.             }
  66.             Console.WriteLine(max);
  67.             Console.WriteLine(x);
  68.             Console.WriteLine(y);
  69.             //второй раз надо пройти чтобы проверить нет ли совпадений чисел
  70.             //int[] kol = new int[300];
  71.             Console.ReadLine();
  72.             int t = 0;
  73.             ar[0, 5] = 99;
  74.             ar[0, 6] = 99;
  75.             ar[0, 7] = 99;
  76.             for (int i = 0; i < 10; i++)
  77.             {
  78.                 for (int j = 0; j < 10; j++)
  79.                 {
  80.                     if (max == ar[i, j])
  81.                     {
  82.                         if (x != i || y != j)
  83.                         {
  84.                             kol1[t] = ar[i, j];
  85.                             t++;
  86.                             kol3[t] = j;
  87.                             kol2[t] = i;
  88.                             t++;
  89.                         }
  90.                     }
  91.                 }
  92.             }
  93.             Console.ReadLine();
  94.            
  95.             gr = t;
  96.             for (int i = 0; i < t+1;i++)
  97.             {
  98.                 Console.Write(kol1[i]);
  99.             }
  100.             Console.ReadLine();
  101.             for (int i = 0; i < t+1; i++)
  102.             {
  103.                 Console.Write(kol2[i]);
  104.             }
  105.             Console.ReadLine();
  106.             for (int i = 0; i < t+1; i++)
  107.             {
  108.                 Console.Write(kol3[i]);
  109.             }
  110.             Console.ReadLine();
  111.  
  112.  
  113.  
  114.  
  115.             t = 0;
  116.  
  117.             while (t < gr + 1)
  118.             {
  119.                 Console.Write("Значение: " + kol1[t]);
  120.                
  121.                 Console.Write(" , его X coor: " + kol2[t]);
  122.                
  123.                 Console.Write(" , его Y coor: " + kol3[t]);
  124.                
  125.                 Console.WriteLine();
  126.                 t++;
  127.                
  128.             }
  129.             //выводим массив по 3 значения
  130.  
  131.  
  132.  
  133.             Console.WriteLine();
  134.         }
  135.     }
  136.  
  137.  
  138.  
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement