find second largest element in array w/o using sorting
techniques? use onle one for loop.
Answer Posted / rajni kant
public class Findarray {
public static void main(String[] args) {
int array[]={250,12,34,56,73,260,232,234,235,240};
int max ,secndmax;
max = array[0];
secndmax=0;// assign it 0 not by array[0]as initial value
System.out.println("Initial value is "+ max);
for (int i=1;i<array.length;i++){
if (array[i]>max ){
secndmax=max;
max=array[i];
}else if(array[i]>secndmax){
secndmax = array[i];
}
}
System.out.println("Max element is "+ max);
System.out.println("Second Max element is "+
secndmax);
}
}
Is This Answer Correct ? | 32 Yes | 11 No |
Post New Answer View All Answers
which type of aspect you want from the student.
i have to apply for rbi before that i need to know the the syllabus for the entrance questions. whethet it may be aps or techinical
Explain what is a program flowchart and explain how does it help in writing a program?
What is a built-in function in C?
Calculate 1*2*3*____*n using recursive function??
PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM
what will be the output for the following main() { printf("hi" "hello"); }
What language is c written?
What do you mean by c what are the main characteristics of c language?
What does main () mean in c?
Explain what are reserved words?
How can you allocate arrays or structures bigger than 64K?
What is difference between Structure and Unions?
Implement bit Array in C.
What is strcmp in c?