Guest User

Untitled

a guest
Mar 1st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     srand(time(NULL));
  9.     int n=30;
  10.     int tab[n];
  11.     for (int g=0;g<n;g++)
  12.     {
  13.         tab[g]=rand()%50;
  14.         cout<<tab[g]<<" ";
  15.     }
  16.     cout<<endl<<endl;
  17.     for(int i=0;i<n;i++)
  18.     {
  19.         for(int j=n-1;j>=0;j--) //użycie for(int j=0;j<=n-1;j++) powoduje, że pierwsze 13 wyrazów jest nieuporządkowane
  20.         {
  21.             if(tab[j]>tab[j+1])
  22.                  swap(tab[j],tab[j+1]);
  23.            
  24.         }
  25.         cout<<tab[i]<<" ";
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment