#include <iostream>
using namespace std;
int main( )
{
int *str[10] = {NULL };
str[10] = 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;
}
我一运行就出现程序错误!
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;
}
按你说的改不行吖!
我的程序没提示错误,只是一运行 整个平台就错误了!
是不是有逻辑错误吖?!
#include
#include
#include
using namespace std;
int main( )
{
int str[10] = {NULL };
//str[10] = 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;
}