#include <iostream>
using namespace std;
int main()
{
int n, arr[10], i, j, temp, minin;
cin >> n;
for (i = 0; i < n; i++)
{
cin >> arr[i];
}
for (i = 0; i < n - 1; i++)
{
minin = i;
for (j = i + 1; j < n; j++)
{
if (arr[j] < arr[minin])
minin = j;
temp = arr[minin];
arr[minin] = arr[i];
arr[i] = temp;
}
}
for (i = 0; i < n; i++)
{
cout << arr[i];
}
return 0;
}
There are no compile-time errors. But my code does not sort properly.
This is what I get:
INPUT :
4 //size of the array to be sorted
5 3 2 8 //actual array to be sorted
OUTPUT :
3528
The expected output is the sorted array in ascending order.
std::sort
fails to give the student exercise in writing code and learning the language. – Eric Postpischil Aug 5 '20 at 13:47