Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. int s, r, i, poz, p, sum1, sum2, miinR, rind = 0, miin, maax, maxR, minR;
  8. float a;
  9. string b, si;
  10. int x[4][4], f[4], h[4];
  11.  
  12. void arrayF() // masiva aizpilde
  13. {
  14. srand(time(0));
  15. p = 0;
  16. cout << "How to fill array auto or manually" << endl;
  17. do
  18. {
  19. cout << "1 = auto, 2 = manually" << endl;
  20. cin >> b;
  21. stringstream be(b);
  22. be >> a;
  23. if (a == 1)
  24. {
  25. cout << "Array auto fill" << endl;
  26. for (r = 0; r < 4; r++)
  27. {
  28. for (i = 0; i < 4; i++)
  29. {
  30. x[r][i] = rand() % 30 - 20;
  31. }
  32. }
  33. p = 1;
  34. }
  35.  
  36. if (a == 2)
  37. {
  38. cout << "Array manual fill" << endl;
  39. for (r = 0; r < 4; r++)
  40. {
  41. for (i = 0; i < 4; i++)
  42. {
  43. cin >> s;
  44. x[r][i] = s;
  45. s = 0;
  46. }
  47. }
  48. p = 1;
  49. }
  50. } while (p == 0);
  51. }
  52.  
  53. int main()
  54. {
  55. arrayF();
  56. system("cls");
  57. cout << "\n1uzd" << endl; //1uzd
  58. cout << "\nArray of 16 ";
  59. cout << endl
  60. << endl;
  61. for (r = 0; r < 4; r++)
  62. {
  63. for (i = 0; i < 4; i++)
  64. {
  65. if (x[r][i] > 0)
  66. poz = poz + 1;
  67. cout << "\t" << x[r][i];
  68. }
  69. cout << "\n\n";
  70. }
  71. cout << "\nPozitivo skaitlu daudzums = " << poz << endl;
  72. cout << endl;
  73.  
  74. system("pause");
  75. system("cls");
  76. arrayF();
  77. system("cls");
  78.  
  79. cout << "\n2uzd" << endl; //2uzd
  80. cout << "\nArray of 16 ";
  81. cout << endl
  82. << endl;
  83.  
  84. for (r = 0; r < 4; r++)
  85. {
  86. for (i = 0; i < 4; i++)
  87. {
  88. if (i == 1)
  89. {
  90. sum1 = sum1 + x[r][i];
  91. f[r] = x[r][i];
  92. }
  93. if (i == 3)
  94. {
  95. sum2 = sum2 + x[r][i];
  96. h[r] = x[r][i];
  97. }
  98. cout << "\t" << x[r][i];
  99. }
  100. cout << "\n\n";
  101. }
  102.  
  103. cout << "\n Even sum (2) = ";
  104. for (i = 0; i < 4; i++)
  105. {
  106. if (f[i] < 0 && i == 3)
  107. cout << "(" << f[i] << ") = ";
  108. if (f[i] > 0 && i == 3)
  109. cout << f[i] << " = ";
  110. if (f[i] < 0 && i < 3)
  111. cout << "(" << f[i] << ") + ";
  112. if (f[i] >= 0 && i < 3)
  113. cout << f[i] << " + ";
  114. }
  115. cout << sum1 << endl;
  116. cout << endl;
  117.  
  118. cout << "\n Even sum (4) = ";
  119. for (i = 0; i < 4; i++)
  120. {
  121. if (h[i] < 0 && i == 3)
  122. cout << "(" << h[i] << ") = ";
  123. if (h[i] > 0 && i == 3)
  124. cout << h[i] << " = ";
  125. if (h[i] < 0 && i < 3)
  126. cout << "(" << h[i] << ") + ";
  127. if (h[i] >= 0 && i < 3)
  128. cout << h[i] << " + ";
  129. }
  130. cout << sum2 << endl;
  131. cout << endl;
  132.  
  133. system("pause");
  134. system("cls");
  135. arrayF();
  136. system("cls");
  137.  
  138. cout << "\n3uzd" << endl; //3uzd
  139. cout << "\nArray of 16 " << endl;
  140. cout << endl;
  141. for (r = 0; r < 4; r++)
  142. {
  143. cout << r + 1 << ")";
  144. miinR = x[r][0];
  145. for (i = 0; i < 4; i++)
  146. {
  147. cout << "\t" << x[r][i];
  148. if (x[r][i] < miinR)
  149. {
  150. miinR = x[r][i];
  151. }
  152. }
  153. cout << "\tSmallest =" << miinR;
  154. cout << "\n\n";
  155. }
  156. cout << endl;
  157.  
  158. system("pause");
  159. system("cls");
  160. arrayF();
  161. system("cls");
  162.  
  163. poz = 0;
  164.  
  165. cout << "\n4uzd" << endl; //4uzd
  166. cout << "\nArray of 16 " << endl;
  167. cout << endl;
  168. for (r = 0; r < 4; r++)
  169. {
  170. poz = 0;
  171. cout << r + 1 << ")";
  172. for (i = 0; i < 4; i++)
  173. {
  174. cout << "\t" << x[r][i];
  175. if (x[r][i] > 0)
  176. poz = poz + 1;
  177. }
  178. cout << "\n\n";
  179. if (poz == 4 && rind == 0)
  180. {
  181. rind = r + 1;
  182. }
  183. }
  184. cout << "\nPositive line = " << rind << endl;
  185. cout << endl;
  186.  
  187. system("pause");
  188. system("cls");
  189. arrayF();
  190. system("cls");
  191.  
  192. cout << "\n5uzd" << endl; //5uzd
  193. cout << "\nArray of 16 before swap " << endl;
  194. cout << endl;
  195. miin = maax = x[0][0];
  196. minR = maxR = 1;
  197. for (r = 0; r < 4; r++)
  198. {
  199. cout << r + 1 << ")";
  200. for (i = 0; i < 4; i++)
  201. {
  202. cout << "\t" << x[r][i];
  203. if (x[r][i] < miin)
  204. {
  205. miin = x[r][i];
  206. minR = r + 1;
  207. }
  208. if (x[r][i] > maax)
  209. {
  210. maax = x[r][i];
  211. maxR = r + 1;
  212. }
  213. }
  214. cout << "\n\n";
  215. }
  216. cout << "\nSmallest number = " << miin << "\tSmallest number line = " << minR << endl;
  217. cout << "\nBiggest number = " << maax << "\tBiggest number line = " << maxR << endl;
  218. for (i = 0; i < 4; i++)
  219. {
  220. swap(x[maxR - 1][i], x[minR - 1][i]);
  221. }
  222. cout << "\nArray of 16 after swap " << endl;
  223. cout << endl;
  224. for (r = 0; r < 4; r++)
  225. {
  226. cout << r + 1 << ")";
  227. for (i = 0; i < 4; i++)
  228. {
  229. cout << "\t" << x[r][i];
  230. }
  231. cout << "\n\n";
  232. }
  233. cout << endl;
  234.  
  235. system("pause");
  236. return 0;
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement