0

Find second largest

Hi anyone know how to find second largest #include <iostream> using namespace std; int index_Of_Second_Largest_Element(int x[]){ int first; int second; int temp; int len = sizeof(x)/sizeof(x[0]); for(int i = 0; i < len ; i++){ if(i < 1) { if(x[i] > x[i+1]) { first = x[i]; second = x[i+1]; } else{ first = x[i+1]; second = x[i]; } } else if(i > 1){ if(x[i] > first){ second = first; first = x[i]; } } } return second; } int main () { int num [] = {5,9,8,2,3,11,10}; int second_larger = index_Of_Second_Largest_Element (num); cout << "Index of Second Largest Element " << second_larger << endl; return 0; }

16th Dec 2020, 3:17 PM
nur nazhan
nur nazhan - avatar
1 Resposta
0
Hi nur nazhan Try to search the forum by 'second largest' term (without quotes), this topic had been posted several times, in different languages and slight modifications 👍 P.S. And please tag C++ rather than 'helpppp' up there ☝
16th Dec 2020, 4:31 PM
Ipang