Facebook
From Whipped Terrapin, 6 Years ago, written in C++.
This paste is a reply to C++ from Whipped Partdridge - view diff
Embed
Download Paste or View Raw
Hits: 385
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int main()
  7. {  
  8.     int buf;
  9.     int n;
  10.     int tab[10000];
  11.     cout << "Podaj ilosc liczb w tablicy:" << endl;
  12.     cin >> n;
  13.    if (n>0){
  14.    
  15.      cout << "Elementy tablicy: ";
  16.     for (int i = 0; i < n; i++)
  17.     {
  18.         tab[i] = rand() % 100;
  19.         cout << setw(4) << tab[i];
  20.         if (tab[i]>tab[i + 1])
  21.         {
  22.             buf = tab[i];
  23.             tab[i] = tab[i + 1];
  24.             tab[i + 1] = buf;
  25.            
  26.  
  27.         }  
  28.                 cout << " Elementy tablicy: ";
  29. for (int i = 0; i < n; i++)
  30. cout << setw(4) << tab[i];
  31. cout << endl;  
  32.     }
  33.         cout << endl;
  34. }
  35. else
  36. cout << "Uwaga! Podales niewlasciwa liczbe (ujemna)"<< endl;
  37.     system("PAUSE");
  38.     return 0;
  39. }