解题思路:难点在于数组的长度需要人为输入,采用动态数组解决。
注意事项:
参考代码:
#include<iostream>> #include<cmath> using namespace std; int main() { int n; int temp; while (cin >> n) { //跳出循环 if (n == 0) { break; } //采用动态数组 int* point; point = new int[n]; for (int i = 0; i < n; i++) { cin >> point[i]; } //冒泡排序 for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (fabs(point[i]) < fabs(point[j])) { temp = point[i]; point[i] = point[j]; point[j] = temp; } } } //输出 for (int i = 0; i < n; i++) { cout << point[i] << " "; } cout << endl; } return 0; }
0.0分
0 人评分