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

public class Findarray {

public static void main(String[] args) {
int array[]={250,12,34,56,73,260,232,234,235,240};
int max ,secndmax;
max = array[0];
secndmax=0;// assign it 0 not by array[0]as initial value
System.out.println("Initial value is "+ max);
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 ?    32 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what are compound statements?

994


What is a rvalue?

1140


What are loops in c?

953


What are the types of pointers?

1033


What are the valid places to have keyword “break”?

1039


Differentiate between a for loop and a while loop? What are it uses?

1132


main() { printf("hello"); fork(); }

1148


What does main () mean in c?

1059


What are the types of type qualifiers in c?

1032


What is the behavioral difference when include header file in double quotes (“”) and angular braces (<>)?

1272


Hai what is the different types of versions and their differences

1897


What is a function in c?

1485


Is c a great language, or what?

1050


Can you write the algorithm for Queue?

2029


What is the best way of making my program efficient?

962