Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int arrSize;
- int matrix[100];
- int oddNum[100];
- int oddCtr = 0;
- int evenNum[100];
- int evenCtr = 0;
- int temp = 0;
- int a = 0;
- int b = 0;
- cin >> arrSize;
- for(int i = 0; i < arrSize; i++)
- {
- int num = rand() % 1000 + 1;
- matrix[i] = num;
- cout << matrix[i] << " ";
- }
- cout << endl << endl;
- while(a < arrSize)
- {
- if(matrix[a] % 2 != 0)
- {
- oddNum[oddCtr] = matrix[a];
- oddCtr++;
- }
- a++;
- }
- while(b < arrSize)
- {
- if(matrix[b] % 2 == 0)
- {
- evenNum[evenCtr] = matrix[b];
- evenCtr++;
- }
- b++;
- }
- for(int c = 1; c <= oddCtr - 1; c++)
- {
- for(int d = 0; d < oddCtr - c; d++)
- {
- if(oddNum[d] > oddNum[d+1])
- {
- temp = oddNum[d+1];
- oddNum[d+1] = oddNum[d];
- oddNum[d] = temp;
- }
- }
- }
- for(int c = 1; c <= evenCtr - 1; c++)
- {
- for(int d = 0; d < evenCtr - c; d++)
- {
- if(evenNum[d] < evenNum[d+1])
- {
- temp = evenNum[d+1];
- evenNum[d+1] = evenNum[d];
- evenNum[d] = temp;
- }
- }
- }
- for(int e = 0; e <= evenCtr-1; e++)
- {
- matrix[e] = evenNum[e];
- }
- int g = 0;
- int k = evenCtr;
- while(k < arrSize)
- {
- matrix[k] = oddNum[g];
- k++;
- g++;
- }
- for(int j = 0; j < arrSize; j++)
- {
- cout << matrix[j] << " ";
- }
- cout << endl;
- }
- /*
- ----------------------------------------------------------------------------------------------------------------------------------
- ----------------------------------------------------------------------------------------------------------------------------------
- Creates and array with random numbers and sorts them in even numbers in decresing order followed by odd numbers in increasing order
- ----------------------------------------------------------------------------------------------------------------------------------
- ----------------------------------------------------------------------------------------------------------------------------------
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement