find second largest element in array w/o using sorting
techniques? use onle one for loop.
Answer Posted / rajni kant
public class Findarray {
public static void main(String[] args) {
int array[]={250,12,34,56,73,260,232,234,235,240};
int max ,secndmax;
max = array[0];
secndmax=0;// assign it 0 not by array[0]as initial value
System.out.println("Initial value is "+ max);
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 ? | 32 Yes | 11 No |
Post New Answer View All Answers
What are void pointers in c?
What is a pointer in c plus plus?
Is c language still used?
Why static variable is used in c?
What are the features of c languages?
How can I remove the trailing spaces from a string?
What is #include called?
How many identifiers are there in c?
What is the method to save data in stack data structure type?
Calculate 1*2*3*____*n using recursive function??
What is "Hungarian Notation"?
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?
What is function prototype in c language?
hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..
i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none