Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void printArray(int array[100])
- {
- for (size_t i = 0; i < 100; i++)
- {
- cout << array[i] << " ";
- }
- }
- void getArray(int array[100])
- {
- for (size_t i = 0; i < 100; i++)
- {
- cin >> array[i];
- }
- }
- void divideByInterval(int array[100], int arrayOne[100], int arrayTwo[100], int &counterOne, int &counterTwo)
- {
- int a, b;
- cout << "For the interval, enter a: " << endl << "enter b: " << endl;
- cin >> a >> b;
- for (size_t i = 0; i < 100; i++)
- {
- if (array[i] > 0 && array[i] % 2 == 1)
- {
- if (array[i] >= a && array[i] <= b )
- {
- array[counterOne] = array[i];
- counterOne++;
- }
- else
- {
- array[counterTwo] = array[i];
- counterTwo++;
- }
- }
- }
- }
- void sortArray(int array[100], int counter)
- {
- int temp;
- for (size_t i = 0; i < counter; i++)
- {
- for (size_t j = i + 1; j < counter; j++)
- {
- if (array[i] > array[j])
- {
- temp = array[i];
- array[i] = array[j];
- array[j] = temp;
- }
- }
- }
- }
- void thirdArray(int arrayThree[100], int arrayOne[100],int arrayTwo[100], int counterOne, int counterTwo)
- {
- for (size_t i = 0; i < counterOne; i++)
- {
- arrayThree[i] = arrayOne[i];
- }
- for (size_t i = counterOne; i < counterOne + counterTwo ; i++)
- {
- arrayThree[i] = arrayOne[i];
- }
- }
- int main()
- {
- int array[100];
- int arrayOne[100];
- int arrayTwo[100];
- int arrayThree[100];
- int counterOne = 0, counterTwo = 0;
- getArray(array);
- printArray(array);
- divideByInterval(array, arrayOne, arrayTwo, counterOne, counterTwo);
- sortArray(arrayOne, counterOne);
- sortArray(arrayTwo, counterTwo);
- thirdArray(arrayThree, arrayOne, arrayTwo, counterOne, counterTwo);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement