Facebook
From Crimson Pheasant, 6 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 557
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. int main()
  8. {  
  9. int ile, i, p, buf;
  10.  
  11. cout << "Podaj ile ma byc losowych liczb w tablicy:"<<endl;
  12. cin >> ile;
  13. int tab[ile];
  14. srand(time(0));
  15. cout << "Elementy tablicy: ";
  16. for (i=0; i<ile; i++)
  17. {
  18. tab [ile]=rand() %100;
  19. cout <<setw(4) << tab [ile];}
  20. cout << endl;
  21. for (p=p-2; p>=0; p--)
  22.         for (i=0; i<=p; i++)
  23.         if (tab[ile+1]<tab[ile])
  24.         {buf=tab[ile+1];
  25.         tab[ile+1]=tab[ile];
  26.         tab[ile]=buf;
  27.         }
  28.         cout << "Elementy tablicy: ";
  29.         for (i=0; i<ile;i++)
  30.  
  31.         cout << setw(4)<< tab[ile];
  32.         cout << endl;
  33.  
  34.  
  35.  
  36. system("pause");
  37. return 0;
  38. }
  39.