问题描述
请帮忙,任何人都可以指出代码有什么问题
#include <iostream>
using namespace std;
int main() {
int n;
cout << "enter the size of array ";
cin >> n;
int arr[n];
cout << "enter numbers \n";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; i < n; j++) {
if (arr[j] < arr[i]) {
int temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
cout << "the numbers are\n" << endl;
for (int j = 0; j < n; j++) {
cout << arr[j] << " " << endl;
}
return 0;
}
我的问题是为什么这段代码没有对数组进行排序并且在输入后也没有给出输出它也显示分段错误?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)