fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5.  
  6.  
  7. int main()
  8. {
  9. int N;
  10.  
  11. cout << "size array:" << endl;
  12. cin >> N;
  13. if (N > 1 && N < 256) {
  14.  
  15. int* arr = new int[N];
  16.  
  17. bool alreadyThere;
  18. cout << "output of numbers: ";
  19. for (int j = 0; j < N;)
  20. {
  21. alreadyThere = false;
  22. int newRandomValue = rand() % 256;
  23.  
  24. for (int i = 0; i < j; i++)
  25. {
  26. if (arr[i] == newRandomValue)
  27. {
  28. alreadyThere = true;
  29. break;
  30. }
  31. }
  32.  
  33. if (!alreadyThere)
  34. {
  35. arr[j] = newRandomValue;
  36. cout << " " << arr[j];
  37. j++;
  38. }
  39.  
  40. }
  41. }
  42. else
  43. {
  44. cout << "wrong number entered" << endl;
  45. }
  46.  
  47. return 0;
  48.  
  49.  
  50. }
Success #stdin #stdout 0.01s 5496KB
stdin
32
stdout
size array:
output of numbers:  103 198 105 115 81 255 74 236 41 205 186 171 242 251 227 70 124 194 84 248 27 232 231 141 118 90 46 99 51 159 201 154