getpid这个函数在Windows里面是无法使用的
#include <stdio.h>
#include <sys/types.h>#include <unistd.h>
#include <stdlib.h>
int main()
{
int poker,flag[55] = {0};
int i;
srand(getpid());
{
for(i = 0;i <52;i++);
{
poker = rand() % 52;
while(1)
{
poker = rand() % 52;
}
flag[poker] = 1;
if(poker >= 0 && poker <= 12)
{
printf("红桃 %d\n",poker + 1);
}
else if(poker >= 13 && poker <= 25)
{
printf("黑桃 %d\n",poker - 12);
}
else if(poker >= 26 && poker <= 38)
{
printf("方块 %d\n",poker - 25);
}
else if(poker >= 39 && poker <=51)
printf("草花 %d\n",poker - 38);
}
}
return 0;
}
本文展示了一个使用C语言编写的简单程序,该程序通过调用srand()和rand()函数来实现扑克牌的随机洗牌,并按花色打印出来。需要注意的是,在Windows环境下无法使用getpid函数获取进程ID。
4310

被折叠的 条评论
为什么被折叠?



