For the following 2-dimensional grid, please fill the individual holes with card
ID: 3198822 • Letter: F
Question
For the following 2-dimensional grid, please fill the individual holes with cards including clubs, spades, hearts, and diamonds. Once the holes are filled with cards, we want to save the current state in the 2-D, 5x5 array. Please refer to the following card to integer number mapping rule. You need to additionally declare a tally array as a multi-counter (8 pts).
Note: Card to integer number mapping is as follows:
0 Club
1 Spade
2 Heart
3 Diamond
Cards array would be a 2-D, 5x5 array as the above example.
The multi-counter array of integer, named tally would be a 1-D,size 4.
Please assume that the array, cards, is constructed according to a row-major scheme:
Ex) cards[2][1]and cards[4][4] hold value 3.
based on the given card-number mapping rule.
Note: Every time you read an integer number from the cards array, you are to increment the corresponding tally array element.
Please write a program that builds the cards array with the given initial values as above and
build and fill the tally array as you walk through the cards array using 2-dimensional array traversal.
Final output should print both cards and tally arrays.
Thanks
Explanation / Answer
The way you have your shuffling, only the first 13 cards are. To shuffle all 52, use
or add another loop to give a thorough shuffle
1 2 3 4 5 6 7
for (i=0;i<52;i++) { j = (rand()%52)+1; temp = card[i]; card [i] = card[j]; card[j] = temp; }