Question

In: Computer Science

Use C to Write a program that "cuts" a deck of 52 playing cards. Given a...

Use C to

Write a program that "cuts" a deck of 52 playing cards. Given a cut position, the process of cutting the deck refers to taking all cards before the cut position and moving them to the end of the deck. The order of the cards is maintained. For example, if the deck is cut at position 25, the first 25 cards of the deck are moved to become the last 25 cards of the deck. The new first card in the deck is card 26, and the new last card of the deck is card 25.

The deck of cards is represented as a 52-element integer array, with values 1 through 52 representing the different cards. The initial population of the deck is done for you.

Your program should accept a single integer input, which is the cut position. If the input is less than 1 or greater than 52, your program should print "ERROR" and exit. Otherwise, after performing the cut, your program should print out the new deck, with one card value on each line.

Solutions

Expert Solution

void cutDeck(int *deck, int cutPosition) {
        
        if(cutPosition < 1 || cutPosition > 52) {
                printf("Error!\n");
        } else {
                
                // We need to perform n Rotations now.
                int rotations = 0;
                while(rotations++ < cutPosition) {
                        int first = deck[0];
                        for(int i=1; i<52; i++) {
                                deck[i-1] = deck[i];
                        }
                        deck[51] = first;
                }
                
                // Now print the deck.
                for(int i=0; i<52; i++) {
                        printf("%d ", deck[i]);
                }
                printf("\n");
        }


}
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

Write a program in c++ that picks four cards from a deck of 52 cards and...
Write a program in c++ that picks four cards from a deck of 52 cards and computes the sum of the four cards. An Ace, King, Queen, and Jack represent 1, 13, 12, and 11, respectively. Your program should display the number of picks that yields the sum of 24. You are not allowed to use arrays. Declare four variables to hold the card values.
The following question involves a standard deck of 52 playing cards. In such a deck of...
The following question involves a standard deck of 52 playing cards. In such a deck of cards there are four suits of 13 cards each. The four suits are: hearts, diamonds, clubs, and spades. The 26 cards included in hearts and diamonds are red. The 26 cards included in clubs and spades are black. The 13 cards in each suit are: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace. This means there are four...
A deck of playing cards contains 52 cards, half of which are red cards. What is...
A deck of playing cards contains 52 cards, half of which are red cards. What is the probability that the deal of a five-card hand provides: 1) No red cards? 2) At least 3 red cards? a) .325, .025 b) .325, .5 c) .5, .325 d) .025, .50 e) .5, .15
he following question involves a standard deck of 52 playing cards. In such a deck of...
he following question involves a standard deck of 52 playing cards. In such a deck of cards there are four suits of 13 cards each. The four suits are: hearts, diamonds, clubs, and spades. The 26 cards included in hearts and diamonds are red. The 26 cards included in clubs and spades are black. The 13 cards in each suit are: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace. This means there are four...
Two cards are randomly selected from a deck of 52 playing cards. (a) What is the...
Two cards are randomly selected from a deck of 52 playing cards. (a) What is the probability they constitute a pair (that is, that they are of the same denomination)? (b) What is the conditional probability they constitute a pair given that they are of different suits?
Two cards are drawn at random from an ordinary deck of 52 playing cards. If the...
Two cards are drawn at random from an ordinary deck of 52 playing cards. If the two cards display the same suit, you win $2. If they are the same color only, you win $1. Otherwise, you lose 50 cent. Calculate (a) the expected value of the amount you win; (b) the variance of the amount you win;
You draw cards from a standard deck of 52 playing cards. There are 12 “face cards”...
You draw cards from a standard deck of 52 playing cards. There are 12 “face cards” in the deck (J, Q, or K). Let X be the number of drawings (with replacement) it takes until you get your first face card. Let Y be the number of drawings (with replacement) it takes until you get your fifth face card. Let Z be the number of face cards removed if you draw 10 cards without replacement. (a) Calculate P(X = 5)....
You are dealt a hand of five cards from a standard deck of 52 playing cards....
You are dealt a hand of five cards from a standard deck of 52 playing cards. Calculate the probability of the given type of hand. (None of them is a recognized poker hand.) (a) Mixed royal meeting: One of each type or royal card (king, queen, jack, ace) of different suites, and a last non-royal card (neither king, queen, jack or ace). Enter a formula. Examples: C(5,3)C(33,3)/C(14,2) C(5,3)C(33,3)C(4,1)/C(100,100) (b) Red and black double royal wedding: A red king, a red...
You are dealt a hand of five cards from a standard deck of 52 playing cards....
You are dealt a hand of five cards from a standard deck of 52 playing cards. Calculate the probability of the given type of hand. (None of them is a recognized poker hand.) 1. Double royal interracial wedding: Two kings of one color, two queens of the other color, and a last non-royal card (neither king, queen, jack or ace). Solve using a formula. Examples:  C(5,3)C(33,3)/C(14,2) or C(5,3)C(33,3)C(4,1)/C(100,100)
Assume that a standard deck of 52 playing cards is randomly shuffled (13 cards of 4...
Assume that a standard deck of 52 playing cards is randomly shuffled (13 cards of 4 types of suits - clubs, diamonds, hearts, and spades). If Alex draws a card from it 4 times with replacement, how many different combinations of suits can he get? (Suppose we further assume that the order doesn't matter: (clubs, diamonds, hearts, hearts) is equal to (hearts, clubs, diamonds, hearts). However, (clubs, diamonds, hearts, hearts) is different with (hearts, clubs, clubs, hearts).)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT