Nth minimum element in a array

N th minimum element in a array

To find the 'N' th minimum element in the given array

Sample input : array length : 5
                         array element : 10 5 3 8 15
                         nth element : 4
 Sample output : 10

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
int main()
{
    int arr[10],i,j,n,temp,a,min;
    printf("enter the length of array : ");
    scanf("%d",&a);
    printf("enter the array elements : ");
    for(i=0;i<a;i++)
    {
        scanf("%d",&arr[i]);
    }
    printf("Enter the 'n'th min value to find : ");
    scanf("%d",&n);
   for(i=1;i<a;i++) //insertion sort
   {
       temp=arr[i];
       j=i-1;
       while (j>=0 && arr[j]>temp)
       {
           arr[j+1] = arr[j];
           j = j-1;
       }
       arr[j+1] = temp;
   }
    printf("the minimum element in the given pos in array is : %d",arr[n-1]);
    return 0;
}

OUTPUT:


0 comments