MeehoweCK

Untitled

May 6th, 2021
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. const short N=6;
  8.  
  9. bool czy_istnieje(int, int*, int);  // prototyp funkcji
  10.  
  11. void wypelnianie(int tab[])
  12. {
  13.     int n;
  14.     srand(time(nullptr));
  15.  
  16.     for(int i=0; i<N; ++i)
  17.     {
  18.         do
  19.         {
  20.             n = 1+rand()%49;
  21.         } while(czy_istnieje(n, tab, i));
  22.  
  23.         tab[i] = n;
  24.     }
  25. }
  26.  
  27. void wypisz(int tab[])
  28. {
  29.     for(int i=0; i<N; ++i)
  30.     {
  31.         cout << tab[i] << "\t";
  32.     }
  33. }
  34.  
  35.  
  36. bool czy_istnieje(int a, int tab[], int n)
  37. {
  38.     for(int i=0; i<n; ++i)
  39.     {
  40.         if(tab[i]==a) return 1;
  41.     }
  42.     return 0;
  43. }
  44.  
  45.  
  46. int main()
  47. {
  48.     int tab[N];
  49.  
  50.     wypelnianie(tab);
  51.     wypisz(tab);
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment