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


Please Help Members By Posting Answers For Below Questions

which type of aspect you want from the student.

1703


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

1845


Explain what is a program flowchart and explain how does it help in writing a program?

650


What is a built-in function in C?

797


Calculate 1*2*3*____*n using recursive function??

1520






PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM

1717


what will be the output for the following main() { printf("hi" "hello"); }

9340


What language is c written?

578


What do you mean by c what are the main characteristics of c language?

573


What does main () mean in c?

616


Explain what are reserved words?

635


How can you allocate arrays or structures bigger than 64K?

684


What is difference between Structure and Unions?

641


Implement bit Array in C.

678


What is strcmp in c?

601