如何设计一个发牌程序

#include 

int main()
{
	int flag[52] = {0};
	int poker, i;

	srand(time(NULL));

	for(i = 0; i < 52; i++)
	{
		poker = rand() % 52;//产生一个随机数

		while(flag[poker] == 1)//如果重复则重新分配
		{
			poker = rand() % 52;
		}

		flag[poker] = 1;

		if((poker >= 0) && (poker <= 12))
		{
			printf("黑桃%d ", poker + 1);
		}

		else if((poker >= 13) && (poker <= 25))
		{
			printf("红桃%d ", poker - 12);
		}

		else if((poker >= 26) && (poker <= 38))
		{
			printf("草花%d ", poker - 25);
		}

		else
		{
			printf("方块%d ", poker - 38);
		}

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

	return 0;
}

你可能感兴趣的:(C语言习题)