In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "C language how to achieve random card selection program", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "C language how to achieve random card program" it!
Programming requirements
This procedure is responsible for issuing a deck of standard cards, each of which has a variety of colors (clubs, diamonds, spades, hearts) and a grade (2, 3, 4, 4, 5, 6). KJA). The program requires the user to indicate how many cards the phone has.
Programming process
1. Use the library function and the time function, use the time function to return the current time, represent it with a number, and the srand function initializes the C language random number generator. By passing the return value of the time function to srand, you can prevent the program from dealing the same cards every time it runs. The rand function produces random numbers by% scaling.
2. Use a two-digit array to record data. Four rows represent each color, and thirteen columns represent each grade.
3. At the beginning of the program, the array elements are false, each randomly selected a card, check the in_hand corresponding element true or false, if true, then extract other cards, if false, record to the array elements, remind us that this card has been recorded.
Effect display
Complete code
# include # define num_rates ((int) (sizeof (value) / sizeof (value [0])) # define initial_balance 100.00 # define num_suits 4#define num_ranks 13 int main () {bool in_ hand [num _ suits] [num_ranks] = {false}; int num_cards,rank,suit Const char rank_code [] = {'2pm, 3pm, 4J, 5J, 7p, 8p, 9K, 9m, 5m, 5m, 5m, 5m, 5m, 5p, 5m, 5p, 5p, 5p, 5i, 5i, 5pm, 5pm, 5pm, 5pm, 5pm, 5m, 5m, 5m, 5m, 5i, 5i, 5i, 8s, 9s, 8s, 9s, 9s, 8s, 9s, 9s, 8s, 9s, 9s, 8s, 9s, 9s, 9s, 9s, 9s, 9s, 9s, 9s, 9s, 8s, 9s, 9s, 9s, 9s, 9s, 9s, 9s, 9s, 8s, 9s, 9s, 9s, 9s, 9s, 9s, 9s, 9s While (num_cards > 0) {suit = rand ()% num_suits; rank = rand ()% num_ranks; if (! in_ handlers] [rank]) {in_ handlers] [rank] = true; num_cards--; printf ("% c% c", rank_ code [rank], suit_ code [rank]);}} printf ("\ n"); return 0 At this point, I believe you have a deeper understanding of "C language how to achieve random card selection program". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.