房屋中介网站怎么做,山西seo推广系统,建筑人才网首页,wordpress商品采集器程序设计要求
本程序负责发一副标准纸牌#xff0c;每张标准纸牌都有一种花色#xff08;梅花、方块、黑桃、红桃#xff09;和一个等级#xff08;2#xff0c;3#xff0c;4#xff0c;5#xff0c;6…K,A#xff09;。程序需要用户指明手机有几张牌。
程序设计流…程序设计要求
本程序负责发一副标准纸牌每张标准纸牌都有一种花色梅花、方块、黑桃、红桃和一个等级23456…K,A。程序需要用户指明手机有几张牌。
程序设计流程
1 . 使用库函数和时间函数用time函数返回当前时间用一个数表示srand函数初始化C语言的随机数生成器。通过把time函数返回值传递给srand可以避免程序每次运行发同样的牌。rand函数产生随机数通过%缩放。
2 . 使用二位数组来进行数据记录。4行表示每种花色13列表示每种等级。
3 . 程序开始时数组元素都为false每随机抽取一张纸牌时检查in_hand对应元素真假如果为真则抽取其他纸牌如果为假记录到数组元素当中提醒我们这张牌已经记录过了。
效果展示 完整代码
#include stdio.h
#include ctype.h
#include stdbool.h
#include time.h
#include stdlib.h# define num_rates ((int) (sizeof(value)/sizeof(value[0])))
# define initial_balance 100.00#define num_suits 4
#define num_ranks 13int main(){bool in_hand[num_suits][num_ranks] {false};
int num_cards,rank,suit;const char rank_code[] { 2,3,4,5,6,7,8,9,t,j,q,k,a};
const char suit_code[] { c,d,h,s};
printf(enter number\n);
scanf(%d,num_cards);printf(your hands\n);
while(num_cards0){suit rand()%num_suits;rank rand()%num_ranks;if(!in_hand[suit][rank]){in_hand[suit][rank] true;num_cards--;printf( %c%c,rank_code[rank],suit_code[suit]);}
}
printf(\n);
return 0;
}