Problem 29

8 comments on “Problem 29”


  • swagatapal1980

    import java.util.Scanner;
    public class p30FindKthElem {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println(“enter the length of the array : “);
    int n = sc.nextInt();
    System.out.println(“enter the array : “);
    int arr[] = new int[100];
    for(int i = 0; i<n; i++)
    {
    arr[i] = sc.nextInt();
    }
    //sort the array in ascending order
    int i, j;
    for(i = 0; i<n; i++)
    {
    for(j = 1; jarr[j]) {
    int temp = arr[j-1];
    arr[j-1] = arr[j];
    arr[j] = temp;
    }
    }
    }
    System.out.println(“after sorting array elements : “);
    for(i = 0; i<n; i++)
    {
    System.out.print(arr[i]+" ");
    }
    System.out.println();
    System.out.println("enter the index number to be searched : ");
    int k = sc.nextInt();
    System.out.println(arr[k-1]);
    }
    }


  • swagatapal1980

    import java.util.Arrays;
    import java.util.Collections;
    import java.util.Scanner;
    class Main{
    public static void main(String[] args)
    {
    int[] arr= {7, 10, 4,3,20,15};
    Arrays.sort(arr);
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    System.out.println(arr[k-1]);
    }
    }


  • sunny

    python :
    arr=[7,10,4,3,20,15]
    k=int(input())
    arr=sorted(arr)
    print(arr[k-1])


  • Santhosh

    package com.prepInsta.nqt;
    import java.util.*;
    public class SelectionSort {

    public static void main(String[] args)
    {
    Scanner sc=new Scanner(System.in);
    System.out.println(“entert the range”);
    int n=sc.nextInt();
    int a[]=new int[n];
    int min;
    int temp=0;
    for(int i=0;i<n;i++)
    {
    a[i]=sc.nextInt();
    }

    for(int i=0;i<n-1;i++)
    {
    min=i;
    for(int j=i+1;j<n;j++)
    {
    if(a[j]<a[min])
    {
    min=j;
    }
    }
    temp=a[i];
    a[i]=a[min];
    a[min]=temp;

    }
    for(int i=0;i<n;i++)
    {
    System.out.print(a[i]+" ");
    }
    System.out.println("enter the Kth smallest element to be searched:");
    int s=sc.nextInt();
    System.out.print(a[s-1]+" ");

    int l=a.length;

    System.out.println("enter the Sth smallest element to be searched:");
    int k=sc.nextInt();

    System.out.println(a[l-k]);
    }

    }


  • VIVEK KUMAR

    #Python
    arr=[7, 10, 4, 3, 20, 15]
    num=int(input(“Enter the number”))
    arr.sort(reverse=True)
    print(arr[num-1])