find second largest element in array w/o using sorting
techniques? use onle one for loop.
Answer Posted / abhineet
package myPackage;
public class BiggestElementInArray {
public static void main(String agrgs[]){
int arr[] = {10,-1,-2,8,-3,-4,-5};
int max = arr[0];
int scndMax=max;
for(int i=1;i<arr.length;i++){
if(max<arr[i]){
scndMax = max;
max = arr[i];
}else if(arr[i]>scndMax || max==scndMax ){
scndMax = arr[i];
}
}
System.out.println("max::"+max);
System.out.println("scndMax::"+scndMax);
}
}
| Is This Answer Correct ? | 11 Yes | 8 No |
Post New Answer View All Answers
What does it mean when a pointer is used in an if statement?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
What is the use of linkage in c language?
What is a good way to implement complex numbers in c?
How to write c functions that modify head pointer of a linked list?
Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.
Why do we use stdio h and conio h?
Explain how can I open a file so that other programs can update it at the same time?
What are the types of pointers?
Explain Basic concepts of C language?
FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)} a.error b. c. d.
Can you explain the four storage classes in C?
What is identifier in c?
What is pass by value in c?
Explain high-order and low-order bytes.