设计一个算法,要求在20个数字中(0-19)随机选取十个数字,但是这十个数字不能重复.

[复制链接]
查看11 | 回复2 | 2013-7-9 15:40:41 | 显示全部楼层 |阅读模式
#include#include#include#includebool f[20];int main(){ memset(f,true,sizeof(f)); srand(unsigned(time(0))); for (int i=1;i<=10;i++) {bool find=false;int r;while (!find){ int x=rand()%20; find=f[x]; r=x;}f[r]=false;printf("%d\n",r); } return 0;}[您的采纳是我们前进的不竭动力]...
回复

使用道具 举报

千问 | 2013-7-9 15:40:41 | 显示全部楼层
我用BASIC写吧,上面有人用C写的。dim i as integerdim j as integerdim h as integerdim num(10) as integer '十个数字for i=0 to 9num(i)=-1loop:j=rnd()*20 for h=0 to 9
if num(...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行