100个随机数中有10个小于20 c++

[复制链接]
查看11 | 回复0 | 2009-10-29 21:57:55 | 显示全部楼层 |阅读模式
#include #include using namespace std;int main(int argc, char *argv[]){
srand(0);
int i,p;
for(i=1;i#include /*输出函数定义,a代表要输出的整数,b代表当前是第几个数,c代表一行输出几个数*/void print( int a, int b, int c ){
printf("%5d",a);
if( 0 == b%c )
{
printf("\n");
}}void main(){
int nCount = 0;
/*记录在0到20间的个数*/
int nTemp,nCnt = 1;
/*nTemp存储产生的随机数,nCnt计数器*/
while( nCnt20 && nTemp20 )
{
print( nTemp, nCnt, 10 );
nCnt++;
}
/*否则继续产生符合条件的随机数*/
else
{
;
}
}
getch();}
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行