# Problem 2

### 30 comments on “Problem 2”

• Ujjawal

def sort(arr):

for i in range(len(arr)):
minpos=i
for j in range(i+1,len(arr)):
if arr[j]<arr[minpos]:
minpos=j

arr[i],arr[minpos]=arr[minpos],arr[i]

arr=list(map(int,input().split()))
sort(arr)
print(*arr)

• dee.pansh18johri

in C++
#include
using namespace std;

int main() {

int n;
cin>>n;
int a[n];
for(int i=0;i>a[i];
for(int i=0;i<n-1;i++)
{
int idx=i;
int mini=a[i];
for(int j=i+1;ja[j])
{
mini=a[j];
idx=j;
}
}
int t=a[idx];
a[idx]=a[i];
a[i]=t;
}
for(int i=0;i<n;i++)
cout<<a[i];
return 0;
}
@DEEPANSH JOHRI

• Gourav

arr=list(map(int,input().split()))
for i in range (len(arr)):
minn=arr[i]
flag=False
for j in range (i,len(arr)):
if(minn>arr[j]):
minn=arr[j]
MIN_OF=arr[j]
flag=True
print(MIN_OF)
if(flag==True):
arr[arr.index(MIN_OF)],arr[i]=arr[i],arr[arr.index(MIN_OF)]
print(arr)

• Rahul

int main()
{
int x;
scanf(“%d”,&x);
int arr[x];
int small,temp;
for(int i=0;i<x;i++)
{
scanf("%d",&arr[i]);
}
for(int i=0;i<x-1;i++)
{
small=i;
for(int j=i+1;jarr[j])
small=j;
}
temp=arr[small];
arr[small]=arr[i];
arr[i]=temp;

}
for(int i=0;i<x;i++)
{
printf("%d ",arr[i]);
}
return 0;
}