#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int paixu(int ,int);//洗牌声明
int main(){
int a[4][13],d,i,j,m,num=0,t=0,b[52]={0};
srand(time(NULL));
for(i=0;i<4;i++){
for(j=0;j<13;j++){
a[i][j]=j+1;
}
}
for(;num<=52;){
d=rand()%52;
for(m=0;m<num;m++){
if(d==b[m]){
break;
}
}
if(m==num){
b[num]=d;
switch(d/13){
case 0:printf("红桃");break;
case 1:printf("方块");break;
case 2:printf("草花");break;
case 3:printf("黑桃");break;
}
num++;
b[t++]=a[d/13][d%13];
printf("%2d%c",a[d/13][d%13],num%13==0 && num!=0?'\n':' ');
}
paixu(0,13);paixu(13,26);paixu(26,39);paixu(39,52);
}
}return 0;
}
int paixu(int m,int n) //洗牌函数
{ for(i=m;i<n;i++)
for(j=n-1;j>i;j++)
if(b[j-1]>b[j])
{
t=b[j];b[j]=b[j-1];b[j-1]=t;
x=0;
for(x<13) printf("%2d",b[x++]); return 0;
}
}
Adrop
0
Newbie Poster
Recommended Answers
Jump to Post1. Learn to use code tags. The code you posted is almost impossible to read without them.
2. What is the problem with your program? What does it not do that you want it to do? Are there any compiler errors? If yes, then what are thy?
Jump to PostWell, you used code tags, but the formatting is still horrible. I you can't bothe to indent your program properly then I won't bother to read it.
All 5 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Adrop
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Adrop
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.