+ 1
Single dimensional array
#How can i get second largest and second smallest number in any array? I want logic with different different methods?
5 odpowiedzi
+ 21
Hy Umesh Sharma
● simple way to solve this is to sort array in ascending order & then taking out values at index n-2 & 1.
● U can click on profile pic of user to get to his SL profile
+ 2
thank you gaurav. but with sorting i knw but i want without sorting concept.. thats why i am here actully.... i done with sorting but without sorring i want.
thanks buddy again👍
0
You should first get the largest and the smallest numbers in the array, then go through the array and check every number that is greater then previous number and smaller then largest number.
For the second smalles do same thing but check for every number that is smaller then previous and greater then smallest number!
for example:
int arr[6] = {1, 2, 3, 4, 5, 6};
int secondMax = 0;
int secondMin = 0;
for(int i = 0; i < 6; i++)
{
if( arr[i] > secondMax && i < 6)
secondMax = arr[i];
}
for(int i = 0; i < 6; i++)
{
if(arr[i] < secondMin && i > 1)
secondMin = arr[i];
}
0
thank you sekiro....thank you so much.....
0
by the way, where you from? what you do? from which country?