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 the second maximum in an array?

Answer Posted / fish

int a1(int[] a)
{
int max1 = -1;
int max2 = -1;

for (int i=0; i<a.length; i++)
{
if (a[i] > max1)
{
max2 = max1;
max1 = a[i];
}
else if (a[i] != max1 && a[i] > max2)
max2 = a[i];
}

return max2;
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

In what situations do you have to use initialization list rather than assignment in constructors?

1011


Show the application of a dynamic array with the help of an example.

1072


What is doubly linked list in c++?

1027


Why we use #include iostream in c++?

989


What is the difference between a "copy constructor" and an "assignment operator" in C++?

1015


Why do we need function?

1000


Is c++ proprietary?

1010


Explain the difference between class and struct in c++?

984


Can there be at least some solution to determine the number of arguments passed to a variable argument list function?

958


There are 100 students in a class. The management keep information in two tables. Those two tables are given like Roll no Name Age 001 ABC 15 002 XYZ 14 and Roll No Subject Marks 001 Math 75 001 Physics 55 002 Math 68 001 Hindi 69 They want the information like this Roll No Name Hindi Physics Math Total 001 ABC 69 55 75 199 002 XYZ 68 74 84 226 And Roll No Suject Highest 001 Math 98 007 Physics 84 021 Hindi 74 All 275 All information is kept in structure in main memory. You have to find last two tables.

2941


What is size_type?

968


Write about the access privileges in c++ and also mention about its default access level?

1006


What are smart pointers?

2161


What is the difference between #import and #include in c++?

1057


What are the steps in the development cycle?

1032