#include
using namespace std;
int main( )
{
int *str = NULL ;
str = new int [10];
srand(time(0)); //改变随机数序列
for ( int i=0; i<10; ++i)
{
str[i]=rand()%101; //生成10个0-100之间的随机数
}
cout << "排列前得数组为:";
for(int i = 0; i < 10 ; ++i)
{
cout << str[i] << " ";
}
cout << endl;
for( int i = 0; i < 9 ; ++i)
{
for( int j = i+1; j < 10 ; ++j)
{
if( str[i] < str[j])
{
int temp = str[j];
str [j] = str[i];
str[i] = temp;
}
}
}
cout << "排列后的数组为:";
for( int i = 0; i < 10 ; ++i)
{
cout << str[i] << " ";
}
return 0;
}
关键在这里开始赋值错:*str[i]=rand()%101; //生成10个0-100之间的随机数