#include <iostream>
using namespace std;
#define LEN 10 // 数组长度
int main() {
int a[LEN];
// 生成原始数据
for (int i = 0; i < LEN; ++i) {
a[i] = rand() % 100; // 生成[0, 99]的随机数
cout << a[i] << '\t';
}
cout << endl;
// 排序
sort(a, a + LEN); // sort(begin,end),表示一个范围
// 输出排序后的结果
for (int i = 0; i < LEN; ++i) {
cout << a[i] << '\t';
}
return 0;
}
输出
7 49 73 58 30 72 44 78 23 9
7 9 23 30 44 49 58 72 73 78
Process finished with exit code 0