Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. using namespace std;
  4.  
  5. void sortuj(int tab[])
  6. {
  7.     int i = 0;
  8.     int j = 0;
  9.     for(i; i < 20; i++)
  10.     {
  11.         for(j=i; j < 20; j++)
  12.         {
  13.             if(tab[j]<tab[i])
  14.             {
  15.                 swap(tab[j], tab[i]);
  16.             }
  17.         }
  18.     }
  19. }
  20.  
  21. void wyswietl_tablice(int tab[])
  22. {
  23.     int i = 0;
  24.     for(i; i < 20; i++)
  25.     {
  26.         cout << tab[i] << " ";
  27.     }
  28. }
  29. int main()
  30. {
  31.     int tab[20];
  32.     srand(time(NULL));
  33.     for(int i = 0; i < 20; i++)
  34.     {
  35.         tab[i] = rand()%20;
  36.     }
  37.     wyswietl_tablice(tab);
  38.     cout << endl;
  39.     sortuj(tab);
  40.     wyswietl_tablice(tab);
  41.     cout << endl;
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement