Advertisement
Vickyyy01

RandowArrayDecreasing

Jan 13th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int arrSize;
  9.     cin >> arrSize;
  10.     int matrix[100];
  11.     int temp = 0;
  12.  
  13.     for(int i = 0; i < arrSize; i++)
  14.     {
  15.         int num = rand() % 1000 + 1;
  16.         matrix[i] = num;
  17.         cout << matrix[i] << " ";
  18.     }
  19.  
  20.     cout << endl << endl;
  21.  
  22.     for(int i = 1; i <= arrSize - 1; i++)
  23.     {
  24.         for(int j = 0; j < arrSize - i; j++)
  25.         {
  26.             if(matrix[j] < matrix[j+1])
  27.             {
  28.                 temp = matrix[j+1];
  29.                 matrix[j+1] = matrix[j];
  30.                 matrix[j] = temp;
  31.             }
  32.         }
  33.     }
  34.  
  35.     for(int k = 0; k < arrSize; k++)
  36.     {
  37.         cout << matrix[k] << " ";
  38.     }
  39.     cout << endl;
  40. }
  41.  
  42. /*
  43. -------------------------------------------------------------------------------------------------------------------------------
  44. -------------------------------------------------------------------------------------------------------------------------------
  45. Generates array with random number elements and then sorts it in decreasing order using Bubble Sort.
  46. -------------------------------------------------------------------------------------------------------------------------------
  47. -------------------------------------------------------------------------------------------------------------------------------
  48. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement