📄 subject_42107.htm
字号:
<p>
序号:42107 发表者:liveyou 发表日期:2003-05-31 20:45:05
<br>主题:请教一个算法.
<br>内容:请教:在50个数中,随机抽取5个数的语句,怎么写//
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:liveyou 回复日期:2003-05-31 20:55:34
<br>内容:快来帮帮我呀各位...<BR><BR><BR>还有什么地方,有C 的源代码下载呀...我想要纸牌游戏的源代码.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:试一试 回复日期:2003-05-31 21:53:23
<br>内容: //昨晚刚在这里贴了一贴,你又来?<BR> //不过看你那么急,顺手再贴一个吧<BR><BR>//按F1得到的<BR><BR>Example<BR>/* RAND.C: This program seeds the random-number generator<BR> * with the time, then displays 10 random integers.<BR> */<BR><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <time.h><BR><BR>void main( void )<BR>{<BR> int i;<BR><BR> /* Seed the random-number generator with current time so that<BR> * the numbers will be different every time we run.<BR> */<BR> srand( (unsigned)time( NULL ) );<BR><BR> /* Display 10 numbers. */<BR> for( i = 0; i < 10;i++ )<BR> printf( " %6d\n", rand() );<BR>}<BR><BR>Output<BR> 6929<BR> 8026<BR> 21987<BR> 30734<BR> 20587<BR> 6699<BR> 22034<BR> 25051<BR> 7988<BR> 10104<BR><BR>//下面才是你想要的<BR><BR> int numSrc[50];//假定数据放在这里<BR> int numDst[5];//假定你要把数据放在这里<BR><BR> int iFound=0;//已经找到的个数<BR><BR> while(iFound++<5)<BR> {<BR> srand( (unsigned)time( NULL ) );<BR><BR> int iRand = rand();<BR> iRand %= 49;//将随机数限制在0-49以内<BR> <BR> numDst[iFound] = numSrc[iRand] //就是你想要的<BR><BR> }<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -