Advertisement
sheredega

Task #4

Dec 10th, 2022
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.     srand(time(NULL));
  7.     int arr[6];
  8.     int num;
  9.     bool already;
  10.     for (int i = 0; i < 6; i++) {
  11.         already = false;
  12.         num = 1 + rand() % (49 - 1 + 1);
  13.         for (int j = 0; j < 6; j++) {
  14.             if (arr[j] == num) {
  15.                 already = true;
  16.             }
  17.         }
  18.         if (already == true) {
  19.             i--;
  20.         }
  21.         else {
  22.             arr[i] = num;
  23.         }
  24.     }
  25.     cout << "Our numbers:\n";
  26.     for (int i = 0; i < 6; i++) {
  27.         cout << arr[i] << " ";
  28.     }
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement