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

What is the type of this pointer in c++?

1062


Write a program which employs Recursion

1233


How do I run c++?

1061


What do manipulators do?

1009


What are the unique features of C++.

1073


Const char *p , char const *p What is the difference between the above two?

1208


How do we balance an AVL Tree in C++?

1126


Draw a flow chart and write a program for the difference between the sum of elements with odd and even numbers. Two dimensional array.

6402


What is a namespace in c++?

2016


What is c++ redistributable?

1225


What is pair in c++?

1063


How would you use the functions randomize() and random()?

1071


What is the best c++ book for beginners?

1145


What is a lambda function c++?

1099


What is static in c++?

1055