Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. void InitArray(const int, int*, const int, const int);
  9. void PrintArray(const int, const int*);
  10. void ChooseMethod(int*, const int);
  11. void Work(int*, int);
  12.  
  13. void main()
  14. {
  15.     SetConsoleOutputCP(1251);
  16.     SetConsoleCP(1251);
  17.  
  18.     const int lenght = 30; int min = -15; int max = 20;
  19.     int array[lenght];
  20.     InitArray(lenght, array, min, max);
  21.     printf("Вхідний масив:\n");
  22.     PrintArray(lenght, array);
  23.     printf("\n");
  24.     Work(array, lenght);
  25.     printf("Вихідний масив:\n");
  26.     PrintArray(lenght, array);
  27.     printf("\n");
  28.     //ChooseMethod(array, lenght);
  29.     system("pause");
  30. }
  31. void InitArray(const int n, int *mas, const int a, const int b)
  32. {
  33.     srand(time(0));
  34.     for (int i = 0; i < n; i++)
  35.     {
  36.         mas[i] = a + rand() % (b - a + 1);
  37.     }
  38. }
  39. void PrintArray(const int n, const int *mas)
  40. {
  41.     for (int i = 0; i < n; i++)
  42.     {
  43.         printf("%3d ", mas[i]);
  44.     }
  45. }
  46. void ChooseMethod(int *mas, const int lenght = 30)
  47. {
  48.     sort(mas, mas + lenght);
  49. }
  50. void Work(int *mas, int lenght)
  51. {
  52.     int a = 0,
  53.         b = 0;
  54.  
  55.     for (int i = 0; i < lenght; i++)
  56.     {
  57.         if ((abs(mas[i] % 2) == 0))
  58.             a = mas[i];
  59.         else
  60.             continue;
  61.         do
  62.         {
  63.             if (mas[i] % 2 == 0)
  64.                 b = mas[i];
  65.             i++;
  66.         } while (i != lenght - 1);
  67.         printf("%d, %d", a, b);
  68.    
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement