What is wrong in this code , It is not displaying the output

#include
using namespace std;
void SelectionSort(int a[],int n)
{
int i,j;
for(int i=0;i<n-1;i++)
{ int min_index=i;
for(j=i;i<n;j++)
{
if(a[j]<a[min_index])
{
min_index=j;
}
}
swap(a[i],a[min_index]);

}
for(int i=0;i<n;i++)
{

    cout<<a[i];
}

}

int main()
{
int a[1000],n,key;

cin>>n;
for(int i=0;i<n;i++)
{
    cin>>a[i];
}
//This is the algorithm of selection sort.
SelectionSort(a,n);

return 0;

}

Output:
5
5 43 3 21 0

Process returned -1073741819 (0xC0000005) execution time : 22.662 s
Press any key to continue.

Hey @coala008 ,
You were iterating j and using the test condition for i that is why the code was not showing correct output.
I have corrected the solution and added comments


Have a look at the solution . Hope it helps !! happy coding