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 the difference between functions getch() and getche()?
Write a program to generate random numbers in c?
Why doesnt long int work?
Why clrscr is used in c?
What is typeof in c?
program to find out date after adding 31 days to a date in the month of febraury also consider the leap year
Do pointers need to be initialized?
What are global variables and how do you declare them?
What are pointers? What are different types of pointers?
swap 2 numbers without using third variable?
Can we use visual studio for c?
What is the symbol indicated the c-preprocessor?
What is substring in c?
What are the types of operators in c?
to find the closest pair