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

How do you sort filenames in a directory?

701


What are multibyte characters?

639


When do we get logical errors?

633


What are the valid places to have keyword “break”?

645


What are the complete rules for header file searching?

664






What is c token?

601


What is the size of array float a(10)?

650


Difference between linking and loading?

686


If null and 0 are equivalent as null pointer constants, which should I use?

573


Write a program that accept anumber in words

1247


What does %c do in c?

578


Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?

972


how to create duplicate link list using C???

2068


shorting algorithmS

1797


Where static variables are stored in memory in c?

519