ranee

повтор максимума

Jun 20th, 2020 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Specialized;
  4. using System.Dynamic;
  5. using System.Linq;
  6. using System.Runtime.Serialization;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace CSLight
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             int maxElement = int.MinValue;
  17.             int repeatNumber = 0;
  18.             int[,] array = new int[10, 10];
  19.             Random rand = new Random();
  20.             for (int i = 0; i < array.GetLength(0); i++)
  21.             {
  22.                 for (int j = 0; j < array.GetLength(1); j++)
  23.                 {
  24.                     array[i, j] = rand.Next(1, 99);
  25.                     Console.Write(array[i, j] + "\t");
  26.                     if (maxElement < array[i, j])
  27.                     {
  28.                         maxElement = array[i, j];
  29.                     }
  30.                 }
  31.                 Console.WriteLine();
  32.             }
  33.             Console.WriteLine();
  34.             Console.WriteLine();
  35.             for (int i = 0; i < array.GetLength(0); i++)
  36.             {
  37.                 for (int j = 0; j < array.GetLength(1); j++)
  38.                 {
  39.                     if (maxElement == array[i, j])
  40.                     {
  41.                         repeatNumber++;
  42.                         array[i, j] = 0;
  43.                     }
  44.                     Console.Write(array[i, j] + "\t");
  45.                 }
  46.                 Console.WriteLine();
  47.             }
  48.             Console.WriteLine($"Максимальное число: {maxElement}, число повторяетя: {repeatNumber}.");
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment