1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
const int row = 4;
const int col = 4;
void showArray (int array [][col]);
void shuffleCards (int array [][col]);
int main () {
srand (time(0));
int myArray [row][col];
shuffleCards(myArray);
showArray(myArray);
return 0;
}
//------------------------------------------------------------------------------------------------
void showArray (int array [][col]) {
for (int i = 0; i < col; i++) {
for (int j = 0; j < row; j++) {
cout << array[i][j];
}
cout << endl;
}
}
//------------------------------------------------------------------------------------------------
void shuffleCards(int cards[][col]) {
int array [row][col] = { {1,1,2,2},
{3,3,4,4},
{5,5,6,6},
{7,7,8,8} };
for (int s=0; s <= 20; s++){
int x = rand() % 4;
int y = rand() % 4;
for (int i=0; i<row; i++) {
int temp=array[i][i];
array[i][i]=array[x][y];
array[x][y]=temp;
}
}
showArray(array);
}
//------------------------------------------------------------------------------------------------
|