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


Please Help Members By Posting Answers For Below Questions

What is use of null pointer in c?

563


How do I use void main?

626


Explain union. What are its advantages?

611


Write a program to print “hello world” without using semicolon?

667


an expression contains relational operators, assignment operators, and arithmatic operstors. In the absence of parentheses, they will be evaluated in which of the following order a) assignment, relational, arithematic b) arithematic, relational, assignment c) relational, arithematic, assignment d) assignment, arithematic, relational

805






What is difference between structure and union in c?

538


What are the advantages of using macro in c language?

585


Why do we need volatile in c?

738


What is the concatenation operator?

604


int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer

647


What is the use of gets and puts?

595


Are negative numbers true in c?

595


Wt are the Buses in C Language

2746


How to write c functions that modify head pointer of a linked list?

539


Explain threaded binary trees?

670