我写了个程序 错误百出 又没改出来 现在急着要用 求求各位大侠帮下忙啊(请在12月18号早上8点前回复)#include<stdio.h> #include<stdlib.h> #include<time.h> int randnum(int n);/*随机数产生函数*/ void shuffle(int deck[][13]);/*洗牌函数原形*/ void deal(const char * [],const char * [],const int [][13]);/*发牌函数原形*/ void main () { char * suit[4]={"Hearts","blocks","spides","clubs"}; char * face[13]={"A","2","3","4","5","6","7","8","9","10","J","Q","K"}; int deck[4][13]={0};/*原始4*13的数组*/ int i,j; shuffle(deck); deal(suit,face,deck); }
void shuffle(int deck[4][13])/*每次产生一个随机的行和列,如果他们对应的数组值不为零,则把发牌序号赋给它*/ {for(int card=1;card<=52;card++)/*循环52次,52个发牌序号*/ {int row=randnum(3); int line=randnum(12); while(deck[row][line]!=0) { row=randnum(3); line=randnum(12); } deck[row][line]=card; } }
void deal(const char * suit,const char * face,const int deck[][13]) { for(int card=1;card<=52;card++) for(int i=0;i<4;i++) for(int j=0;j<13;j++) {if(deck[i][j]==card) printf("%s""of""%s",face[i], suit[j]); if(card%4==0) printf("\n");} }
int randnum(int n) { srand(time(NULL));//be careful,here must be NULL but not null return rand()%(n+1); }