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
What is the explanation for the dangling pointer in c?
What is a function in c?
I heard that you have to include stdio.h before calling printf. Why?
i have a written test for microland please give me test pattern
What is the difference between NULL and NUL?
What is wrong with this statement? Myname = 'robin';
In C language, a variable name cannot contain?
Define C in your own Language.
What is malloc and calloc?
Why can’t we compare structures?
What is the difference between functions getch() and getche()?
write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.
What is dynamic variable in c?
What is the easiest sorting method to use?
What is hashing in c?