find second largest element in array w/o using sorting
techniques? use onle one for loop.
Answer Posted / paresh thorat
package pkg;
public class Number {
public static void main(String [] args){
//int arr[]={6,4,5,2};
int arr[]={1,2,3,4,5};
int max,min=0,i;
max=arr[0];
try {
for(i=1;i<arr.length;i++){
System.out.println("Loop start");
if(arr[i]>max){
min=max;
max=arr[i];
System.out.println("Large->array "+max+"->"+arr[i]);
}
System.out.println("min-> array "+min+"->"+arr[i]);
if(max>arr[i] && arr[i]>min){
System.out.println("I am in second if loop");
min = arr[i];
System.out.println("Now min is "+min);
}
}
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Second Large"+min);
}
}
Is This Answer Correct ? | 5 Yes | 4 No |
Post New Answer View All Answers
What does volatile do?
in any language the sound structure of that language depends on its a) character set, input/output function, its control structures b) character set, library functions, input/output functions its control structures c) character set, library functions, control sturctures d) character set, operators, its control structures
write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1
What does c value mean?
write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.
What is the best way of making my program efficient?
How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same
What are different storage class specifiers in c?
Write a program to print all permutations of a given string.
What is c token?
why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???
I have seen function declarations that look like this
Explain the use of 'auto' keyword
What is spaghetti programming?
Why is structure padding done in c?