随机取扑克牌中10张牌

#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#define MaxStack 100


int stack[MaxStack];
int top = -1;


int push(int value)
{
if (top>=MaxStack)
{
printf("栈内容全满!\n");
return -1;
}
top++;
stack[top] = value;
}


int pop()
{
int temp;
if (top<0)
{
printf("栈内容是空的!\n");
return -1;
}
temp = stack[top];
top--;
return temp;
}


int empty()
{
if (top == -1)
{
return 1;
}
else
return 0;
}


void main()
{
int card[52];
int pos;
int i,temp;
long temptime;


srand(time(&temptime)%60);
for(i=0;i<52;i++)
card[i] = 0;
i = 0;
while(i != 10)
{
pos = rand()%52;
if (card[pos] == 0)
{
push(pos);
card[pos] = 1;
i++;
}
}
while(!empty())
{
temp = pop();
printf("[%c%2d]",temp/13+3,temp%13+1);
}
printf("\n");
}


结果:


你可能感兴趣的:(随机取扑克牌中10张牌)