Advertisement
MeehoweCK

Untitled

May 24th, 2024
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. const int ROZMIAR{ 6 };
  7.  
  8. bool czyJuzJest(int liczba, int tablica[], int n) {
  9.     for (auto i{ 0 }; i < n; ++i) {
  10.         if (tablica[i] == liczba) {
  11.             return true;
  12.         }
  13.     }
  14.     return false;
  15. }
  16.  
  17. void wypelni(int tab[]) {
  18.     for (int i = 0; i < ROZMIAR; ++i) {
  19.         int losowa;
  20.         do {
  21.             losowa = rand() % 49 + 1;
  22.         } while (czyJuzJest(losowa, tab, i));
  23.         tab[i] = losowa;
  24.     }
  25. }
  26.  
  27. void wyswietl(int tab[]) {
  28.     for (int i = 0; i < ROZMIAR; ++i) {
  29.         cout << tab[i] << ' ';
  30.     }
  31.     cout << endl;
  32. }
  33.  
  34. int main() {
  35.     int tab[ROZMIAR];
  36.     srand(time(nullptr));
  37.     wypelni(tab);
  38.     wyswietl(tab);
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement