一个简单的发牌程序
#include "stdio.h"#include "time.h"
#include "stdlib.h"
#define num_suits 4
#define num_ranks 13
#define true 1
#define false 0
void main()
{
char in_hand[num_suits][num_ranks]={0};
const char ranks_code[]={'2','3','4','5','6','7','8','9','10','j','q','k','a'};
const char suits_code[]={'c','d','h','s'};
int suits,ranks,num_cards;
printf("Enter number of cards in hand:\n");
scanf("%d",&num_cards);
srand(time(0));
printf("your hand:\n");
while(num_cards>0)
{
if(num_cards>52)
{
printf("error\n");
break;
}
suits=rand()%num_suits;
ranks=rand()%num_ranks;
if(!in_hand[suits][ranks])
{
in_hand[suits][ranks]=true;
num_cards--;
printf("%c %c\n",suits_code[suits],ranks_code[ranks]);
}
}
}