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

What are void pointers in c?

574


What is a pointer in c plus plus?

690


Is c language still used?

533


Why static variable is used in c?

548


What are the features of c languages?

624






How can I remove the trailing spaces from a string?

609


What is #include called?

565


How many identifiers are there in c?

576


What is the method to save data in stack data structure type?

600


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

1511


What is "Hungarian Notation"?

633


Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?

597


What is function prototype in c language?

608


hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..

1462


i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none

640