题目:设计一个洗牌发牌的程序

#include

int main()
{
int n,i;
int flag[52]= {0};
srand((unsigned int)time(NULL));

for(i = 0; i < 52; i++)
{
n = rand()%52;
while(flag[n] == 1)
{
n = rand()%52;
}
flag[n] = 1;

if(n >= 0 && n < 13)
{
printf("红心%d ", n + 1);
}
else if(n >= 13 && n < 26)
{
printf("黑桃%d ", n - 12);
}
else if(n >= 26 && n < 39)
{
printf("梅花%d ",n - 25);
}
else
{
printf("方片%d ",n - 38);
}


if((i +1) % 13 == 0)
printf("\n");
}
return 0;

}


运行结果:


你可能感兴趣的:(程序)