Advertisement
frentzy

ex 15

May 23rd, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <time.h>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. void main() {
  10.     srand(unsigned(time(NULL)));
  11.     int a[6] = { 5, 9, 10, 15, 25, 26 };
  12.     int b[6] = { 0 };
  13.     int n = 6;
  14.  
  15.     for (int i = 0; i < 5;) {
  16.         int random = rand() % 6;
  17.         bool enter = true;
  18.         for (int index = 0; index < 6; index++) {
  19.             if (a[random] == b[index]) {
  20.                 enter = false;
  21.                 break;
  22.             }
  23.         }
  24.         if (enter) {
  25.             b[i] = a[random];
  26.             i++;
  27.         }
  28.     }
  29.     for (int i = 0; i < n - 1; i++) {
  30.         cout << b[i]<<" ";
  31.     }
  32.     _getch();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement