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

When is dynamic checking necessary?

1059


Why c++ is called oop?

1063


What is purpose of new operator?

1028


What is the size of integer variable?

1022


write a programme to get a character and thier ASCII value

3007


What is c++ vb?

1038


What is the difference between passing by reference and passing a reference?

1033


What is atoi?

930


What is #include iomanip?

961


What is a singleton c++?

951


What is difference between rand () and srand ()?

1049


What is buffering in c++?

1022


What operator is used to access a struct through a pointer a) >> b) -> c) *

1067


What is the most useful programming language?

1005


Why c++ does not have finally?

1033