编写程序生成20个200到300之间的随机整数存放到数组中

更新时间:02-03 教程 由 挽木琴 分享

编写程序生成20个200到300之间的随机整数存放到数组中?

#include

#include

#include

#include

using namespace std;

void main()

{

int a[20];

int sum = 0;

srand((unsigned)(time(0)));//要初始化随机数种子避免随机数序列重复

for(int i=0; i<20; i++)

{

a[i] = rand()%101+200;//闭区间[200,300]

if(!(a[i]%5))

{

cout<

sum+=a[i];

}

}

cout<<"sum="<

readkey();

}

声明:关于《编写程序生成20个200到300之间的随机整数存放到数组中》以上内容仅供参考,若您的权利被侵害,请联系13825271@qq.com
本文网址:http://www.25820.com/tutorial/14_2291842.html