+ 1
Function
https://code.sololearn.com/cfgfqG92PKWf/?ref=app Can someone help me please with this code. There is a mistake in calling the function....
3 Answers
+ 1
#include <iostream>
using namespace std;
int index_Of_Second_Largest_Element(int num[] );
int n, num[10], largest, second, array;
int main(){
cout<<"Enter number of elements: ";
cin>>n;
for(int array=0; array<n; array++){
cout<<"Enter Array Element"<<(array+1)<<": ";
cin>>num[array];
}
cout<<"The index of the second Largest Element is: "<<index_Of_Second_Largest_Element(num); //1 edited
}
int index_Of_Second_Largest_Element(int num[]){ //2 edit
if(num[0]<num[1]){
largest = num[1];
second = num[0];
}
else{
largest = num[0];
second = num[1];
}
for (int array = 2; array< n ; array ++) { //Edit 3
if (num[array] > largest) {
second = largest;
largest = num[array];
}
else if (num[array] > second && num[array] != largest) {
second = num[array];
}
} //Edit 4
return second;
}
//hope you find out mistakes... Or reply...
+ 2
You're welcome đVolley
+ 1
Thank you so much JayakrishnađŽđł â¤ď¸â¤ď¸â¤ď¸đ This is what I want