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
Write the program with at least two functions to solve the following problem. The members of the board of a small university are considering voting for a pay increase for their 10 faculty members. They are considering a pay increase of 8%. Write a program that will prompt for and accept the current salary for each of the faculty members, then calculate and display their individual pay increases. At the end of the program, print the total faculty payroll before and after the pay increase, and the total pay increase involved.
Why isnt any of this standardized in c?
How can I get random integers in a certain range?
When should you use a type cast?
What is c mainly used for?
Why do we need functions in c?
Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.
What is call by value in c?
Explain what are linked list?
How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?
How do you define a function?
Where we use clrscr in c?
What is anagram in c?
What is structure data type in c?
Explain the difference between structs and unions in c?