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 / 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


Please Help Members By Posting Answers For Below Questions

Why is void main used?

1104


Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

1098


how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

1947


Explain what will be the outcome of the following conditional statement if the value of variable s is 10?

1260


Tell us two differences between new () and malloc ()?

1208


What are the types of data types and explain?

1094


Sir i need notes for structure,functions,pointers in c language can you help me please

2428


What is property type c?

1098


application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above

1075


In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none

1218


What is array within structure?

1131


What are the various types of control structures in programming?

1067


Explain what are binary trees?

1086


What is pass by reference in functions?

855


code for quick sort?

2046