TargeTPoweR

Замена наибольшего элемента на 0 в массиве

Mar 25th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 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 Tasks
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int maxNumber = int.MinValue;
  14. int line = 0;
  15. int column = 0;
  16. int[,] array = { { 1,2,3,4,5,6,7,8,9,10},
  17. {11,12,13,14,15,16,17,18,19,20 },
  18. {31,32,33,34,35,36,37,38,39,40 },
  19. {41,42,43,44,45,46,47,48,49,50 },
  20. {51,52,53,54,55,56,57,58,59,60 },
  21. {61,62,63,64,65,66,67,68,69,70 },
  22. {71,72,73,74,75,76,198,78,79,80 },
  23. {81,82,83,84,85,86,87,88,89,90 },
  24. {91,92,93,94,95,96,97,98,99,55}};
  25.  
  26. Console.WriteLine("Исходная матрица выглядит так: ");
  27. Console.WriteLine();
  28.  
  29. for (int i = 0; i < array.GetLength(0); i++)
  30. {
  31. for (int j = 0; j < array.GetLength(1); j++)
  32. {
  33. Console.Write(array[i, j] + " ");
  34. if (array[i, j] > maxNumber)
  35. {
  36. maxNumber = array[i, j];
  37. line = i;
  38. column = j;
  39. }
  40. }
  41. Console.WriteLine();
  42. }
  43. Console.WriteLine();
  44. Console.WriteLine("Максимальное число в матрице: " + maxNumber);
  45.  
  46. array[line, column] = 0;
  47.  
  48. Console.WriteLine();
  49. Console.WriteLine("Полученная матрица выглядит так: ");
  50. Console.WriteLine();
  51.  
  52. for (int i = 0; i < array.GetLength(0); i++)
  53. {
  54. for (int j = 0; j < array.GetLength(1); j++)
  55. {
  56. Console.Write(array[i, j] + " ");
  57. }
  58. Console.WriteLine();
  59. }
  60. }
  61. }
  62. }
Add Comment
Please, Sign In to add comment