Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. void main() {
  6. const int SIZE = 10;
  7. int i;
  8. int array[SIZE] = { 3, 0, 6, 5, 9, 2, 9, 8, 1, 0 };
  9.  
  10. cout << "Massiv:";
  11. for (i = 0; i < SIZE; i++) {
  12. cout << array[i] << " ";
  13. }
  14. cout << "\n" << endl;
  15.  
  16. cout << "1)-------------------\n";
  17. cout << "Chetnie:\n";
  18. int even = array[0];
  19. for (i = 0; i < SIZE; i++) {
  20. if (array[i] % 2 == 0) {
  21. even = array[i];
  22. cout << array[i] << " ";
  23. }
  24. }
  25. cout << endl;
  26.  
  27. cout << "\nNechetnie:\n";
  28. int odd = array[0];
  29. for (i = 0; i < SIZE; i++) {
  30. if (array[i] % 2 == 1) {
  31. odd = array[i];
  32. cout << array[i] << " ";
  33. }
  34. }
  35. cout << endl;
  36.  
  37. cout << "\n2)-------------------\n";
  38. cout << "Min and Max:\n";
  39. int min = array[0];
  40. for (i = 0; i < SIZE; i++) {
  41. if (array[i] < min) {
  42. min = array[i];
  43. }
  44. }
  45. int max = array[0];
  46. for (i = 0; i < SIZE; i++) {
  47. if (array[i] > max) {
  48. max = array[i];
  49. }
  50. }
  51. cout << min << " " << max << endl;
  52.  
  53. cout << "\n3)-------------------\n";
  54. cout << "Min elementy:\n";
  55. int min2 = array[0];
  56. int count = 0;
  57. for (i = 0; i < SIZE; i++) {
  58. if (array[i] < min2) {
  59. min2 = array[i];
  60. count = 1;
  61. }
  62. else if (array[i] == min2) {
  63. count++;
  64. }
  65. }
  66. for (i = 0; i < count; i++)
  67. cout << min2 << " ";
  68. cout << endl;
  69.  
  70. cout << "\nMax elementy:\n";
  71. int max2 = array[0];
  72. count = 0;
  73. for (i = 0; i < SIZE; i++) {
  74. if (array[i] > max2) {
  75. max2 = array[i];
  76. count = 1;
  77. }
  78. else if (array[i] == max2) {
  79. count++;
  80. }
  81. }
  82. for (i = 0; i < count; i++)
  83. cout << max2 << " ";
  84. cout << endl;
  85.  
  86. cout << "\n4)-------------------\n";
  87. cout << "Min and Max, First and Last\n";
  88. int first = array[0];
  89. int last = array[0];
  90. count = 0;
  91. for (i = 0; i < SIZE; i++) {
  92. count++;
  93. }
  94. last = array[count - 1];
  95.  
  96. cout << min << " " << max << " " << first << " " << last << endl;
  97.  
  98. cout << "\n5)-------------------\n";
  99. cout << "Zamena:\n";
  100. int max3 = array[0];
  101. int min3 = array[0];
  102. int maxPosition = 0;
  103. int minPosition = 0;
  104. for (i = 0; i < SIZE; i++) {
  105. if (array[i] > max3) {
  106. max3 = array[i];
  107. maxPosition = i;
  108. }
  109. if (array[i] < min3) {
  110. min3 = array[i];
  111. minPosition = i;
  112. }
  113. }
  114. array[minPosition] = first;
  115. array[0] = min3;
  116. array[maxPosition] = last;
  117. array[SIZE - 1] = max3;
  118.  
  119. for (int i = 0; i < SIZE; i++) {
  120. cout << array[i] << " ";
  121. }
  122. cout << endl;
  123. array[minPosition] = min;
  124. array[0] = first;
  125. array[maxPosition] = max;
  126. array[SIZE - 1] = last;
  127.  
  128. cout << "\n6)-------------------\n";
  129. cout << "Arithmetic mean:\n";
  130. float sum = 0;
  131. for (i = 0; i < SIZE; i++) {
  132. sum += array[i];
  133. }
  134. float mid = sum / SIZE;
  135. cout << mid << endl;
  136.  
  137. cout << "\n7)-------------------\n";
  138. cout << "Summa chisel massiva posle pervogo nulya:\n";
  139. sum = 0;
  140. bool firstnull = false;
  141. for (int i = 0; i < SIZE; i++) {
  142. if (array[i] == 0) {
  143. firstnull = true;
  144. }
  145. if (firstnull == true) {
  146. sum += array[i];
  147. }
  148. }
  149. cout << sum << endl;
  150.  
  151. cout << "\n8)-------------------\n";
  152. cout << "SecondMax:\n";
  153. int smax = array[0];
  154. for (i = 0; i < SIZE; i++) {
  155. if (array[i] > smax && array[i] < max) {
  156. smax = array[i];
  157. }
  158. }
  159. cout << smax << endl;
  160.  
  161. cout << "\n9)-------------------\n";
  162. cout << "Kolichestvo razlichnih elementov massiva:\n";
  163.  
  164.  
  165. cout << "\n10)------------------\n";
  166. count = 0;
  167. for (i = 0; i < SIZE; i++) {
  168. if (array[i] != 0) {
  169. swap(array[count++], array[i]);
  170. }
  171. }
  172. for (i = 0; i < SIZE; i++) {
  173. cout << array[i] << " ";
  174. }
  175. cout << "\n" << endl;
  176.  
  177. system("pause");
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement