killdaclick

Tomek Zadanie 1

Nov 17th, 2019
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <vector>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     cout << "Ile liczb chcesz wylosowac: ";
  11.     int ile_liczb {0};
  12.     cin >> ile_liczb;
  13.    
  14.     srand(time(NULL));
  15.  
  16.    
  17.     vector<int> losowe;
  18.     for(int i=0; i < ile_liczb ; i++)
  19.     {
  20.         int b = rand() % 99+1;
  21.         losowe.push_back(b);
  22.         cout << losowe.at(i)<< " ";
  23.     }
  24.    
  25.     for(int i=0; i < ile_liczb-1 ; i++)
  26.     {if(losowe[i+1] < losowe[i])
  27.         {
  28.             swap(losowe[i], losowe[i+1]);
  29.         }
  30.     }  
  31.    
  32.     cout << "\n";
  33.    
  34.     for(int i=0; i<ile_liczb; i++)
  35.     {
  36.         cout << losowe[i] << " " ;
  37.     }
  38.     cout << endl;
  39.    
  40.    
  41. }
Add Comment
Please, Sign In to add comment