Code works fine in ide but when submitting in challenge windows showing unexpected outputs
#include
using namespace std;
void insertion(int a[],int n)
{
int i,j,smallest;
for (i=1;i<n;i++)
{
smallest=i;
for (j=i-1;j>=0;j–)
{
if(a[j]>a[smallest])
{
swap(a[j],a[smallest]);
smallest=j;
}
}
}
}
int main()
{
int n;
cin>>n;
int a[n];
int i;
for (i=0;i<n;i++)
{
cin>>a[i];
}
insertion (a,n);
for (i=0;i<n;i++)
{
cout<<a[i]<<endl;
}
}