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 are loops in c?
application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above
if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.
how to count no of words,characters,lines in a paragraph.
What does it mean when the linker says that _end is undefined?
What is the use of pointers in C?
Differentiate between full, complete & perfect binary trees.
Is a pointer a kind of array?
Why is c platform dependent?
When would you use a pointer to a function?
What is a pointer and how it is initialized?
what are non standard function in c
write a proram to reverse the string using switch case?
Write a program to print "hello world" without using a semicolon?
What are the different types of C instructions?