创建function,在制定抽签池数量,随机抽取五个数字,
抽到的数字不能重复
抽前后询问是否再抽
最终输出中奖名单
你好代码供参考
function choujiang(n)
allhaoma = randsample(1:n,n);
max_ntimes = floor(n/5);
allhaoma = reshape(allhaoma,max_ntimes,5);
haoma = zeros(size(allhaoma));
count=0;
while(1)
if(count~=0)
flag=input('是否再抽?(是输入1否则输入0)\n');
else
flag=1;
end
if(flag==1)
count = count + 1;
haoma(count,:) = allhaoma(count,:);
fprintf('你已经抽取%d组了\n',count);
else
break;
end
if(count==max_ntimes)
fprintf('奖池号码抽取见底了!抽奖结束\n')
break;
end
end
fprintf('你的本期共抽取%d组号码,分别是:\n',count);
for i = 1:1:count
fprintf('第%d组号码:%d %d %d %d %d\n',i, haoma(i,:));
end
end
示例:
choujiang(100)
你已经抽取1组了
是否再抽?(是输入1否则输入0)
1
你已经抽取2组了
是否再抽?(是输入1否则输入0)
1
你已经抽取3组了
是否再抽?(是输入1否则输入0)
1
你已经抽取4组了
是否再抽?(是输入1否则输入0)
1
你已经抽取5组了
是否再抽?(是输入1否则输入0)
1
你已经抽取6组了
是否再抽?(是输入1否则输入0)
1
你已经抽取7组了
是否再抽?(是输入1否则输入0)
1
你已经抽取8组了
是否再抽?(是输入1否则输入0)
1
你已经抽取9组了
是否再抽?(是输入1否则输入0)
1
你已经抽取10组了
是否再抽?(是输入1否则输入0)
0
你的本期共抽取10组号码,分别是:
第1组号码:19 64 47 98 37
第2组号码:89 59 7 49 34
第3组号码:20 99 9 97 6
第4组号码:15 16 75 26 45
第5组号码:35 94 84 53 88
第6组号码:86 8 68 14 48
第7组号码:10 74 65 93 44
第8组号码:73 77 39 55 18
第9组号码:5 87 72 76 60
第10组号码:81 27 40 78 52