Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. // ConsoleApplication 3.1(B).cpp: определяет точку входа для консольного приложения.
  2. //
  3. #include "stdafx.h"
  4. #include <iomanip>
  5. #include <iostream>
  6. #define size 10
  7.  
  8. using namespace std;
  9.  
  10. int Menu();
  11. void Console(int array[size]);
  12. void Random(int array[size]);
  13. void Initialization(int array[size]);
  14. void View(int array[size]);
  15.  
  16. int main()
  17. {
  18.  
  19. int b[size], a[size];
  20. int i = 0;
  21. int c = 0;
  22.  
  23. switch (Menu())
  24. {
  25. case 1:
  26. {
  27. Console(a);
  28. break;
  29. }
  30. case 2:
  31. {
  32. Random(a);
  33. break;
  34. }
  35. case 3:
  36. {
  37. Initialization(a);
  38. }
  39. }
  40.  
  41. cout << "\narray \n";
  42. View(a);
  43. cout << endl;
  44.  
  45. for (i = 0; i < size; i++)
  46. {
  47. if (a[i] <= 0)
  48. {
  49. b[c] = a[i];
  50. c++;
  51. }
  52. }
  53.  
  54. for (i = 0; i < size; i++)
  55. {
  56. if (a[i]>0)
  57. {
  58. b[c] = a[i];
  59. c++;
  60. }
  61. }
  62.  
  63. cout << "\nnew narray \n";
  64. View(b);
  65.  
  66. system("pause");
  67. return 0;
  68. }
  69.  
  70. int Menu()
  71. {
  72. int item;
  73.  
  74. do
  75. {
  76. cout << "1 - console input\n2 - random\n3 - initialization" << endl;
  77. cin >> item;
  78. } while (item < 0 && item > 3);
  79.  
  80. return item;
  81. }
  82.  
  83. void Console(int array[size])
  84. {
  85. int i;
  86.  
  87. cout << "enter ur array:\n";
  88.  
  89. for (i = 0; i < size; i++)
  90. {
  91. cout << "array[" << i << "] = ";
  92. cin >> array[i];
  93. }
  94. }
  95.  
  96. void Random(int array[size])
  97. {
  98. int i, m, n;
  99.  
  100. do
  101. {
  102. cout << "enter m and n:\n";
  103. cin >> m >> n;
  104. } while (m >= n);
  105.  
  106.  
  107. srand(time(NULL));
  108.  
  109. for (i = 0; i < size; i++)
  110. {
  111. array[i] = rand() % (n - m + 1) + m;
  112. //cout << "a[" << i << "] = " << a[i];
  113. cout << endl;
  114. }
  115. }
  116.  
  117. void Initialization(int array[size])
  118. {
  119. array[0] = 1; array[1] = 3;
  120. array[2] = -1; array[3] = 0;
  121. array[4] = 31; array[5] = -12;
  122. array[6] = 21; array[7] = 5;
  123. array[8] = -2; array[9] = 0;
  124. }
  125.  
  126. void View(int array[size])
  127. {
  128. int i;
  129.  
  130. for (i = 0; i < size; i++)
  131. cout << array[i] << endl;
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement