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;
- cin >> arrSize;
- int matrix[100];
- int temp = 0;
- for(int i = 0; i < arrSize; i++)
- {
- int num = rand() % 1000 + 1;
- matrix[i] = num;
- cout << matrix[i] << " ";
- }
- cout << endl << endl;
- for(int i = 1; i <= arrSize - 1; i++)
- {
- for(int j = 0; j < arrSize - i; j++)
- {
- if(matrix[j] < matrix[j+1])
- {
- temp = matrix[j+1];
- matrix[j+1] = matrix[j];
- matrix[j] = temp;
- }
- }
- }
- for(int k = 0; k < arrSize; k++)
- {
- cout << matrix[k] << " ";
- }
- cout << endl;
- }
- /*
- -------------------------------------------------------------------------------------------------------------------------------
- -------------------------------------------------------------------------------------------------------------------------------
- Generates array with random number elements and then sorts it in decreasing order using Bubble Sort.
- -------------------------------------------------------------------------------------------------------------------------------
- -------------------------------------------------------------------------------------------------------------------------------
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement