Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What does it mean when a pointer is used in an if statement?

1068


main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }

1471


What is the use of linkage in c language?

1018


What is a good way to implement complex numbers in c?

1006


How to write c functions that modify head pointer of a linked list?

950


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

1938


Why do we use stdio h and conio h?

1042


Explain how can I open a file so that other programs can update it at the same time?

1066


What are the types of pointers?

1045


Explain Basic concepts of C language?

1090


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.

1712


Can you explain the four storage classes in C?

1081


What is identifier in c?

974


What is pass by value in c?

1022


Explain high-order and low-order bytes.

1057