Advertisement
totobac

Untitled

Jan 12th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void printArray(int array[100])
  5. {
  6.     for (size_t i = 0; i < 100; i++)
  7.     {
  8.         cout << array[i] << " ";
  9.     }
  10. }
  11.  
  12. void getArray(int array[100])
  13. {
  14.     for (size_t i = 0; i < 100; i++)
  15.     {
  16.         cin >> array[i];
  17.     }
  18. }
  19.  
  20. void divideByInterval(int array[100], int arrayOne[100], int arrayTwo[100], int &counterOne, int &counterTwo)
  21. {
  22.  
  23.     int a, b;
  24.     cout << "For the interval, enter a: " << endl << "enter b: " << endl;
  25.     cin >> a >> b;
  26.  
  27.     for (size_t i = 0; i < 100; i++)
  28.     {
  29.         if (array[i] > 0 && array[i] % 2 == 1)
  30.         {
  31.             if (array[i] >= a && array[i] <= b )
  32.             {
  33.                 array[counterOne] = array[i];
  34.                 counterOne++;
  35.             }
  36.  
  37.             else
  38.             {
  39.                 array[counterTwo] = array[i];
  40.                 counterTwo++;
  41.             }
  42.         }
  43.     }
  44.    
  45. }
  46.  
  47. void sortArray(int array[100], int counter)
  48. {
  49.     int temp;
  50.    
  51.         for (size_t i = 0; i < counter; i++)
  52.         {
  53.             for (size_t j = i + 1; j < counter; j++)
  54.             {
  55.                 if (array[i] > array[j])
  56.                 {
  57.                     temp = array[i];
  58.                     array[i] = array[j];
  59.                     array[j] = temp;
  60.                 }
  61.             }
  62.         }
  63. }
  64. void thirdArray(int arrayThree[100], int arrayOne[100],int arrayTwo[100], int counterOne, int counterTwo)
  65. {
  66.     for (size_t i = 0; i < counterOne; i++)
  67.     {
  68.         arrayThree[i] = arrayOne[i];
  69.     }
  70.    
  71.     for (size_t i = counterOne; i < counterOne + counterTwo ; i++)
  72.     {
  73.         arrayThree[i] = arrayOne[i];
  74.     }
  75. }
  76. int main()
  77. {
  78.    
  79.     int array[100];
  80.     int arrayOne[100];
  81.     int arrayTwo[100];
  82.     int arrayThree[100];
  83.     int counterOne = 0, counterTwo = 0;
  84.     getArray(array);
  85.     printArray(array);
  86.     divideByInterval(array, arrayOne, arrayTwo, counterOne, counterTwo);
  87.     sortArray(arrayOne, counterOne);
  88.     sortArray(arrayTwo, counterTwo);
  89.     thirdArray(arrayThree, arrayOne, arrayTwo, counterOne, counterTwo);
  90.     return 0;
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement