My issue
output coming is correct even though error coming
#include<bits/stdc++.h>
using namespace std;
int n, arr[100000];
int main() {
cin >> n;
// Check if the user input more elements than the array can hold.
/* if (n > 1000) {
return 1;
}*/
// Input the elements of the array.
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
// Sort the array in non-decreasing order.
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[i] > arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
// Print the sorted array.
for (int i = 0; i < n; i++) {
cout << arr[i] << endl;
}
return 0;
}
turbo sort please help
My code
#include<bits/stdc++.h>
using namespace std;
int n, arr[100000];
int main() {
cin >> n;
// Check if the user input more elements than the array can hold.
/* if (n > 1000) {
return 1;
}*/
// Input the elements of the array.
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
// Sort the array in non-decreasing order.
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[i] > arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
// Print the sorted array.
for (int i = 0; i < n; i++) {
cout << arr[i] << endl;
}
return 0;
}
Learning course: Sorting using C++
Problem Link: CodeChef: Practical coding for everyone