daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest May 24th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <clocale>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. auto main() -> int {
  7.     setlocale(LC_ALL, "polish");
  8.     srand(time(NULL));
  9.    
  10.     // bubble sort
  11.    
  12.     int howMuch = 0;
  13.    
  14.     std::cout << "Ile liczb chcesz losować: ";
  15.         std::cin >> howMuch;
  16.     int tab[howMuch];
  17.    
  18.     for (int i = 0; i < howMuch; ++i)
  19.         tab[i] = rand()%1000+1;
  20.        
  21.     std::cout << "Wylosowane liczby to: ";
  22.     for (int i = 0; i < howMuch; ++i)
  23.         std::cout << i+1 << ". " << tab[i] << std::endl;
  24.        
  25.     // sortowanie
  26.     for (int i = 0; i < howMuch; ++i) {
  27.         for (int j = 0; j < howMuch-1; ++j) {
  28.             if (tab[j] > tab[j+1]) std::swap(tab[j], tab[j+1]);
  29.         }
  30.     }
  31.    
  32.     std::cout << "Posortowane liczby to: ";
  33.     for (int i = 0; i < howMuch; ++i)
  34.         std::cout << i+1 << ". " << tab[i] << std::endl;
  35.  
  36.     return 0;  
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top