Problem 2

5 comments on “Problem 2”


  • 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;}


  • 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


  • 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)