vertc

04-04

Apr 4th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int iloscele() {
  8.     int n;
  9.     cout<<"Podaj ilosc elementow n: "<<endl;
  10.     cin>>n;
  11.     return n;
  12. }
  13.  
  14. void gen(int tab[], int n) {
  15.     srand(time(0));
  16.     for(int i=0;i<n;i++) {
  17.         tab[i] = rand()%100+1;
  18.     }
  19.     cout<<endl<<"Liczby zostaly wygenerowane."<<endl;
  20. }
  21.  
  22. int wyswietl(int tab[], int n) {
  23.     cout<<"Wygenerowane liczby to: ";
  24.     for(int i=0;i<n;i++) {
  25.         cout<<tab[i]<<" ";
  26.     }
  27. }
  28. int main() {
  29.     int wybor=5,i=0,n;
  30.     int tab[i];
  31.         while(wybor!=0) {
  32.         cout<<endl<<"______________________________"<<endl;
  33.         cout<<"|0. Wyjscie                   |" <<endl;
  34.         cout<<"|1. Ilosc elementow n         |" <<endl;
  35.         cout<<"|2. Generowanie tablicy       |" <<endl;
  36.         cout<<"|3. Wyswietlanie              |" <<endl;
  37.         cout<<"|_____________________________|" <<endl;
  38.         cout<<endl<<"Wybierz dzialanie (0, 1, 2 lub 3): ";
  39.         cin>>wybor;
  40.         switch(wybor) {
  41.         case 0:
  42.             cout<<endl<<"Wychodzenie z programu...";
  43.             break;
  44.         case 1:
  45.             n = iloscele();
  46.             break;
  47.         case 2:
  48.             gen(tab, n);
  49.             break;
  50.         case 3:
  51.             wyswietl(tab, n);
  52.             break;
  53.         }
  54.     }
  55.     return 0;
  56. }
  57.  
  58. -------------------------------------------------------------------------------------
  59. // WRAZ Z SORTOWANIEM
  60.  
  61. #include <iostream>
  62. #include <cstdlib>
  63. #include <ctime>
  64.  
  65. using namespace std;
  66.  
  67. int iloscele() {
  68.     int n;
  69.     cout<<"Podaj ilosc elementow n: "<<endl;
  70.     cin>>n;
  71.     return n;
  72. }
  73.  
  74. void gen(int tab[], int n) {
  75.     srand(time(0));
  76.     for(int i=0;i<n;i++) {
  77.         tab[i] = rand()%100+1;
  78.     }
  79.     cout<<endl<<"Liczby zostaly wygenerowane."<<endl;
  80. }
  81.  
  82. int wyswietl(int tab[], int n) {
  83.     cout<<"Wygenerowane liczby to: ";
  84.     for(int i=0;i<n;i++) {
  85.         cout<<tab[i]<<" ";
  86.     }
  87. }
  88.  
  89. void sortuj(int tab[], int n) {
  90.     for(int j=0;j<n-1;j++) {
  91.         int temp, pmin = j;
  92.         for(int i=j+1;i<n;i++)
  93.             if(tab[i]<tab[pmin])    pmin = i;
  94.         temp = tab[pmin];
  95.         tab[pmin] = tab[j];
  96.         tab[j] = temp;
  97.     }
  98.     cout<<"Liczby zostaly posortowane.";
  99. }
  100.  
  101. int main() {
  102.     int wybor=5,i=0,n;
  103.     int tab[i];
  104.         while(wybor!=0) {
  105.         cout<<endl<<"______________________________"<<endl;
  106.         cout<<"|0. Wyjscie                   |" <<endl;
  107.         cout<<"|1. Ilosc elementow n         |" <<endl;
  108.         cout<<"|2. Generowanie tablicy       |" <<endl;
  109.         cout<<"|3. Wyswietlanie              |" <<endl;
  110.         cout<<"|4. Sortowanie                |" <<endl;
  111.         cout<<"|_____________________________|" <<endl;
  112.         cout<<endl<<"Wybierz dzialanie (0, 1, 2 lub 3): ";
  113.         cin>>wybor;
  114.         switch(wybor) {
  115.         case 0:
  116.             cout<<endl<<"Wychodzenie z programu...";
  117.             break;
  118.         case 1:
  119.             n = iloscele();
  120.             break;
  121.         case 2:
  122.             gen(tab, n);
  123.             break;
  124.         case 3:
  125.             wyswietl(tab, n);
  126.             break;
  127.         case 4:
  128.             sortuj(tab, n);
  129.             break;
  130.         default:
  131.             cout<<endl<<"Nieprawidlowe polecenie";
  132.             break;
  133.         }
  134.     }
  135.     return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment