Advertisement
Pandarec13

Untitled

Sep 8th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5. class Program
  6. {
  7.  
  8. static void Main()
  9. {
  10.  
  11.  
  12. int a = Convert.ToInt32(Console.ReadLine());
  13. int[] mass = new int[a];// dinamic massive
  14. Console.WriteLine("введите элементы массива");
  15.  
  16. for (int i = 0; i < a; i++)
  17. {
  18. mass[i] = Convert.ToInt32(Console.ReadLine());
  19.  
  20. }
  21.  
  22.  
  23. for (int i = 0; i < a; i++)
  24. {
  25. Console.Write(mass[i] + " ");
  26.  
  27. }
  28.  
  29. int max = -1;
  30. int min = 11;
  31. int num_min = 0;
  32. int num_max = 0;
  33.  
  34. for (int i = 0; i < a; i++)
  35. {
  36. if (mass[i] > max)
  37. {
  38. max = mass[i];
  39. num_max = i + 1;
  40. }
  41.  
  42. if (mass[i] < min)
  43. {
  44. min = mass[i];
  45. num_min = i + 1;
  46. }
  47.  
  48.  
  49. }
  50.  
  51. Console.WriteLine("min= {0} max= {1} min_num= {2} max_num= {3}", min, max, num_min, num_max);
  52.  
  53. // 5 3 2 4 1
  54.  
  55. // 1 2 3 4 5
  56.  
  57. for (int i = 0; i < a; i++)
  58. {
  59.  
  60. for (int j = i + 1; j < a; j++)
  61. {
  62. if (mass[i] < mass[j])
  63. {
  64. int temp;
  65. temp = mass[i];
  66. mass[i] = mass[j];
  67. mass[j] = temp;
  68.  
  69. }
  70. }
  71.  
  72.  
  73. }
  74.  
  75. for (int i = 0; i < a; i++)
  76. {
  77. Console.WriteLine(mass[i]);
  78. }
  79.  
  80.  
  81. //int[] mass_1 = new int[a];
  82. int b = 0;
  83. int[] mass_1 = new int[b];
  84. int ch = 0;
  85. for (int i = 0; i < a; i++)
  86. {
  87.  
  88. if (mass[i] % 2 == 0)
  89. {
  90. //mass_1.
  91. Array.Resize<int>(ref mass_1, b+1);
  92. //mass_1 = new int[4];
  93.  
  94. mass_1[ch] = mass[i];
  95. ch++;
  96. b++;
  97. }
  98. }
  99. Console.WriteLine("---------------------");
  100.  
  101. for (int i = 0; i < mass_1.Length; i++)
  102. {
  103. Console.WriteLine(mass_1[i]);
  104.  
  105. }
  106.  
  107. }
  108.  
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement