What is wrong in this code((insertion sort)?two test cases failing

#include
using namespace std;

int main() {

int n;
cin>>n;

int i,j,x,a[n];
 
  for(i=0;i<n;i++)
  cin>>a[i];
  
for(i=2;i<n;i++)
{
    j=i-1;
    x=a[i];
   for(  ;j>=0 && x<a[j] ;j-- )
      a[j+1]=a[j];

   a[j+1]=x;;
}

for(i=0;i<n;i++)
  cout<<a[i];
return 0;

}

@Asis loop start from i=1 but you are doing from i=2 and put endl in cout statement

#include using namespace std; int main() { int n; cin>>n; int i,j,a[n],min; for(i=0;i<n;i++) cin>>n; for(i=0;i<n-1;i++) { min=i; for(j=i+1;j<n;j++) { if(a[min]>a[j]) min=j; } swap(a[min],a[i]); } for(i=0;i<n;i++) cout<<a[i]<<endl; return 0; }

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.