Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <cstdio>
- #include <algorithm>
- #include <ctime>
- using namespace std;
- void InitArray(const int, int*, const int, const int);
- void PrintArray(const int, const int*);
- void ChooseMethod(int*, const int);
- void Work(int*, int);
- void main()
- {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- const int lenght = 30; int min = -15; int max = 20;
- int array[lenght];
- InitArray(lenght, array, min, max);
- printf("Вхідний масив:\n");
- PrintArray(lenght, array);
- printf("\n");
- Work(array, lenght);
- printf("Вихідний масив:\n");
- PrintArray(lenght, array);
- printf("\n");
- //ChooseMethod(array, lenght);
- system("pause");
- }
- void InitArray(const int n, int *mas, const int a, const int b)
- {
- srand(time(0));
- for (int i = 0; i < n; i++)
- {
- mas[i] = a + rand() % (b - a + 1);
- }
- }
- void PrintArray(const int n, const int *mas)
- {
- for (int i = 0; i < n; i++)
- {
- printf("%3d ", mas[i]);
- }
- }
- void ChooseMethod(int *mas, const int lenght = 30)
- {
- sort(mas, mas + lenght);
- }
- void Work(int *mas, int lenght)
- {
- int a = 0,
- b = 0;
- for (int i = 0; i < lenght; i++)
- {
- if ((abs(mas[i] % 2) == 0))
- a = mas[i];
- else
- continue;
- do
- {
- if (mas[i] % 2 == 0)
- b = mas[i];
- i++;
- } while (i != lenght - 1);
- printf("%d, %d", a, b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement