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
What is use of null pointer in c?
How do I use void main?
Explain union. What are its advantages?
Write a program to print “hello world” without using semicolon?
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
What is difference between structure and union in c?
What are the advantages of using macro in c language?
Why do we need volatile in c?
What is the concatenation operator?
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
What is the use of gets and puts?
Are negative numbers true in c?
Wt are the Buses in C Language
How to write c functions that modify head pointer of a linked list?
Explain threaded binary trees?