Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication 3.1(B).cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iomanip>
- #include <iostream>
- #define size 10
- using namespace std;
- int Menu();
- void Console(int array[size]);
- void Random(int array[size]);
- void Initialization(int array[size]);
- void View(int array[size]);
- int main()
- {
- int b[size], a[size];
- int i = 0;
- int c = 0;
- switch (Menu())
- {
- case 1:
- {
- Console(a);
- break;
- }
- case 2:
- {
- Random(a);
- break;
- }
- case 3:
- {
- Initialization(a);
- }
- }
- cout << "\narray \n";
- View(a);
- cout << endl;
- for (i = 0; i < size; i++)
- {
- if (a[i] <= 0)
- {
- b[c] = a[i];
- c++;
- }
- }
- for (i = 0; i < size; i++)
- {
- if (a[i]>0)
- {
- b[c] = a[i];
- c++;
- }
- }
- cout << "\nnew narray \n";
- View(b);
- system("pause");
- return 0;
- }
- int Menu()
- {
- int item;
- do
- {
- cout << "1 - console input\n2 - random\n3 - initialization" << endl;
- cin >> item;
- } while (item < 0 && item > 3);
- return item;
- }
- void Console(int array[size])
- {
- int i;
- cout << "enter ur array:\n";
- for (i = 0; i < size; i++)
- {
- cout << "array[" << i << "] = ";
- cin >> array[i];
- }
- }
- void Random(int array[size])
- {
- int i, m, n;
- do
- {
- cout << "enter m and n:\n";
- cin >> m >> n;
- } while (m >= n);
- srand(time(NULL));
- for (i = 0; i < size; i++)
- {
- array[i] = rand() % (n - m + 1) + m;
- //cout << "a[" << i << "] = " << a[i];
- cout << endl;
- }
- }
- void Initialization(int array[size])
- {
- array[0] = 1; array[1] = 3;
- array[2] = -1; array[3] = 0;
- array[4] = 31; array[5] = -12;
- array[6] = 21; array[7] = 5;
- array[8] = -2; array[9] = 0;
- }
- void View(int array[size])
- {
- int i;
- for (i = 0; i < size; i++)
- cout << array[i] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement