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 multidimensional arrays?
What is operator precedence?
main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }
What is difference between union All statement and Union?
what are bit fields? What is the use of bit fields in a structure declaration?
What header files do I need in order to define the standard library functions I use?
What is %s and %d in c?
What is ambagious result in C? explain with an example.
Explain how can I avoid the abort, retry, fail messages?
What is c programming structure?
What are Macros? What are its advantages and disadvantages?
In which language linux is written?
i have to apply for the rbi for the post of officers. i need to know abt the entrance questions whether it may be aps or techinical....
How can you determine the maximum value that a numeric variable can hold?
What does it mean when the linker says that _end is undefined?