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
main(){char *str;scanf("%s",str);printf("%s",str); }The error in the above program is: a) Variable 'str' is not initialised b) Format control for a string is not %s c) Parameter to scanf is passed by value. It should be an address d) none
Explain what will the preprocessor do for a program?
Write a program which returns the first non repetitive character in the string?
What do you mean by scope of a variable in c?
Why doesnt that code work?
Why is sizeof () an operator and not a function?
What are the types of i/o functions?
Is void a keyword in c?
What is the translation phases used in c language?
How is = symbol different from == symbol in c programming?
How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?
Can the “if” function be used in comparing strings?
What is the difference between array and pointer?
What are Macros? What are its advantages and disadvantages?
Write a program to swap two numbers without using third variable in c?