find second largest element in array w/o using sorting
techniques? use onle one for loop.
Answer Posted / ranjeet
public static void main(String[] args) {
int array[]={13,12,34,56,73,21,232,234,235,240};
int max ,secndmax;
max = secndmax= array[0];
System.out.println("Initial value is "+ secndmax);
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 ? | 67 Yes | 32 No |
Post New Answer View All Answers
Why is void main used?
Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?
Tell us two differences between new () and malloc ()?
What are the types of data types and explain?
Sir i need notes for structure,functions,pointers in c language can you help me please
What is property type c?
application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above
In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none
What is array within structure?
What are the various types of control structures in programming?
Explain what are binary trees?
What is pass by reference in functions?
code for quick sort?