Guest User

Untitled

a guest
Oct 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. namespace ConsoleApplication20
  2. { class Program
  3. {
  4. static void Main(string[] args)
  5. {
  6. Console.WriteLine("Введите количество элементов в массиве a:");
  7. int n = int.Parse(Console.ReadLine());
  8. int m = int.Parse(Console.ReadLine());
  9.  
  10. int[,] a = new int[n, m];
  11. int s = 0;
  12. double max = a[0, 0];
  13. Random random = new Random();
  14.  
  15. for (int i = 0; i < n; i++)
  16. {
  17. for (int j = 0; j < m; j++)
  18. {
  19. a[i, j] = random.Next(-100, 100);
  20. if (max < a[i, j])
  21. { max = a[i, j]; }
  22. else { s += a[i, j];}
  23. Console.Write("{0,4}", a[i, j]);
  24. }
  25. Console.WriteLine();
  26. }
  27. Console.WriteLine("max = {0}", max);
  28. Console.WriteLine("sum = {0}", s);
  29. Console.ReadKey(true);
  30. }}}
  31.  
  32. if (max < a[i, j])
  33. {
  34. max = a[i, j];
  35. s = 0;
  36. }
  37. else if (a[i, j] % 2 != 0)
  38. {
  39. s += a[i, j];
  40. }
  41.  
  42. using System;
  43. using System.Collections.Generic;
  44. using System.Linq;
  45. using System.Text;
  46.  
  47. namespace tstCons
  48. {
  49. class Program
  50. {
  51. static void Main(string[] args)
  52. {
  53. Console.WriteLine("Введите количество элементов в массиве a:");
  54. int n = int.Parse(Console.ReadLine());
  55. int m = int.Parse(Console.ReadLine());
  56.  
  57. int[,] a = new int[n, m];
  58. int s = 0;
  59. int max = -100; // присваеваем минимальное возможноме значение
  60. int maxI = 0, maxJ = 0; // чтобы запомнить координату максимального элемента
  61. Random random = new Random();
  62.  
  63. for (int i = 0; i < n; i++)
  64. {
  65. for (int j = 0; j < m; j++)
  66. {
  67. a[i, j] = random.Next(-100, 100);
  68. if (max < a[i, j])
  69. {
  70. max = a[i, j];
  71. maxI = i;
  72. maxJ = j;
  73. } // ищем максимум и запоминаем его координаты
  74. Console.Write(a[i, j].ToString() + " ");
  75. }
  76. Console.WriteLine();
  77. }
  78.  
  79. bool flag = false; //исключим максимальный элемент
  80. for (int i = maxI; i < n; i++)
  81. {
  82. for (int j = maxJ; j < m; j++)
  83. {
  84. if (!flag) // если элемент - максимум, то ничего не делаем
  85. {
  86. flag = true;
  87. continue;
  88. }
  89. if (a[i,j]%2 != 0) s += a[i, j]; // проверяем элемент на четность и увеличеваем счетчик
  90. }
  91. }
  92.  
  93. Console.WriteLine("max = {0}", max);
  94. Console.WriteLine("sum = {0}", s);
  95. Console.ReadKey(true);
  96. }
  97. }
  98. }
Add Comment
Please, Sign In to add comment