C++让计算机产生10个随机数并让其按大小排序输出

问题描述:

C++让计算机产生10个随机数并让其按大小排序输出
#include
#include
using namespace std;
int getRand()
{
static int ctrl = 0;
if(!ctrl)
{
srand((unsigned)time(0));
ctrl++;
}
return rand()%31+1;
}
int main()
{
int a[6] = {0};
int num = 0;
for(int i=0;i
1个回答 分类:综合 2014-10-26

问题解答:

我来补答
已经把排序的具体步骤加到你的程序里了!你自己看看吧!
#include
#include
using namespace std;
int getRand()
{
static int ctrl = 0;
if(!ctrl)
{
srand((unsigned)time(0));
ctrl++;
}
return rand()%31+1;
}
int main()
{
int a[6] = {0};
int num = 0;
int t;
for(int i=0;i=0;i--) //排序的具体步骤
{ for(int j=0;ja[j+1])
{t=a[j+1];a[j+1]=a[j];a[j]=t;}
}
}
for(int i=0;i
 
 
展开全文阅读
剩余:2000
下一页:奇偶性的应用。