fork download
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. srand(time(NULL));
  9.  
  10. bool game;
  11. int arr[4][4];
  12.  
  13. for (int i = 0; i < 4; i++)
  14. {
  15.  
  16. for (int j = 0; j < 4;)
  17. {
  18. game = true;
  19. arr[i][j] = rand() % 16;
  20. for (int r = 0; r < 4; r++)
  21. for (int c = 0; c < 4; c++)
  22. {
  23. if (r == i && c == j)
  24. {
  25. r = c = 4;
  26. continue;
  27. }
  28. if (arr[r][c] == arr[i][j])
  29. {
  30. game = false;
  31. r = c = 4;
  32. }
  33. }
  34. if (game == true)
  35. {
  36. j++;
  37. }
  38. }
  39. }
  40.  
  41. for (int i = 0; i < 4; i++)
  42. {
  43. for (int j = 0; j < 4; j++)
  44. cout << arr[i][j] << " ";
  45. cout << "\n";
  46. }
  47. }
Success #stdin #stdout 0s 4508KB
stdin
Standard input is empty
stdout
11 4 3 0 
13 5 7 2 
10 1 12 15 
6 8 9 14