Spread the post

Program to find nth largest number in an array

Given an unsorted array and find the nth largest number or element. suppose array are contain following element.

Stack Areamainarray [0] 5 [1] 8 [2] 2 [3] 4 [4] 1 [5] 4 [6] 6 [7] 7 [8] 8 [9] 22 [10] 34size (int) =11

Views the all largest element sequence.


Note that it's possible to same largest number are two or more element.

Logic and algorithm.

This algorithm print given largest element. but If two or more element same largest priority then it will print only one. so remove break statement then it will print all element with given laregest element.

Iterative C program to find given largest element.


Output


View execution process.

Stack Areamainarray [0] 5 [1] 8 [2] 2 [3] 4 [4] 1 [5] 4 [6] 6 [7] 7 [8] 8 [9] 22 [10] 34size (int) =11nth_largestcounter (int) =1data(pointer)index (int) =7j (int) =2n_th (int) =4size (int) =11status (int) =0

View all execution process.

Try it Yourself

Spread the post

Recommended Posts: