Prime

#### Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

#### Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

# Problem 2

### 10 comments on “Problem 2”

• swapnil

size=int(input())
arr=[int(i) for i in input().split(‘ ‘)]
for i in range(len(arr)):
flag=1
while flag==1:
for j in range(i,len(arr)):
if arr[i]>arr[j]:
t=arr[i]
arr[i]=arr[j]
arr[j]=t
flag=1
break
flag=0
print(arr)

• Nikkala

import java.util.*;
class anil
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int a[]=new int[n];
int temp;
System.out.println(“enter the elements”);
for(int i=0;i<n;i++)
{
a[i]=s.nextInt();
}
for(int i=0;i<n;i++)
{
for(int j=i+1;ja[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println(“sorting of the elements”);
for(int i=0;i<n;i++)
{
System.out.print(a[i]);
}

}
}

• Nikkala

import java.util.*;
public class anil
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int a[]=new int[n];
int temp;
System.out.println(“enter the elements”);
for(int i=0;i<n;i++)
{
a[i]=s.nextInt();
}
for(int i=0;i<n;i++)
{
for(int j=0;ja[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println(“sorting of the elements”);
for(int i=0;i<n;i++)
{
System.out.println(a[i]);
}

}
}

• goutham

#include
using namespace std;
int main()
{int a[9]={13,11,17,5,9,15,21,31,15};
int i,j,b;
for(i=0;i<=7;i++)
{for(j=i+1;j<=8;j++)
{if(a[j]<a[i])
{b=a[i];a[i]=a[j];a[j]=b;}
}
}
for(i=0;i<9;i++)
{cout<<a[i]<<" ";}
return 0;}

• subhojit

#Simple Python Code

arr=[int(x) for x in input().split(” “)]
ct=1
j=0
for i in range(ct,len(arr),1):
z=arr[slice(ct,len(arr))]
index=arr.index(min(z))
if arr[j]>min(z):
arr[j],arr[index]=arr[index],arr[j]
ct+=1
j+=1
print(arr)

• Prakhar

#selection sort
#select min and add in unsorted part
l=list(map(int,input().split()))
for i in range(len(l)):
m=i
for j in range(i+1,len(l)):
if(l[m]>l[j]):
m=j
l[i],l[m]=l[m],l[i]
print(l)

• Srimukhi

#include
int main()
{
int n,i,j,a[100],min=0,temp=0;
printf(“Enter the size of a array : “);
scanf(“%d”,&n);
printf(“Enter the elements into the array : \n”);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
{
min=a[i];
for(j=i+1;j<n;j++)
{
if(min<a[j])
{
min=a[j];
}
}
temp=a[i];
a[i]=min;
min=temp;
}
for(i=0;i<n;i++)
{
printf("%d",a[i]);
}
}
i tried like this but i am not getting the output can u pls help me why

• HelpPrepInsta

Thank you very much for contributing this answer Srimukhi

• Mohd Saif

arr=[14,33,27,10,35,19,42,44]
for i in range(0,len(arr)):
minpos=i
for j in range(i+1,len(arr)):
if(arr[j]<arr[minpos]):
minpos=j
temp=arr[i]
arr[i]=arr[minpos]
arr[minpos]=temp
print(arr)

• naveen k sharma

def selection_sort(arr1):

for i in range(0,len(arr1)):
min_value = i
for j in range(i+1,len(arr1)):
if(arr1[min_value]>arr1[j]):
min_value = j
temp=arr1[min_value]
arr1[min_value] = arr1[i]
arr1[i] = temp
for j in range(0,len(arr1)):
print(arr1[j],end=” “)

if __name__==’__main__’:
n = int(input())
arr1 = [None]*n
for i in range(0,n):
arr1[i] = input()
selection_sort(arr1)