Selection sort array

#include
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n-1;i++){
for(int j=i;j<n;j++){
if(a[j]<a[i]){
swap(a[i],a[j]);
}
}
}
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
return 0;
}
is this program is correct for it please tell me

we can directly do it in it no need to write min index please tell me

yes this is correct
but this is not good approach because you have to perform many swapping operation here.

but if you make one variable min_index then you have to do swapping just once

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.