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

/*Code to write second Minimum Number*/
int[] intarr = { 2, 5, 1, 8, 3, 6, 0, 4, 3, 2, 78, 1, 8 };

int intminval = 0, intsecondminval = 0;

for (int i = 0; i < intarr.Length; i++)
{
if (i == 0)
{
intminval = intsecondminval = intarr[i];
}
else
{
if (intarr[i] < intminval)
{
intsecondminval = intminval;
intminval = intarr[i];

}
else if (intminval == intsecondminval && intarr[i] > intminval)
{
// this conditon is to handle the case
//where the array contains only 2 values
// for e.g. {1,1,2,1,2,2,1}
intsecondminval = intarr[i];
}
}
}

Is This Answer Correct ?    5 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How would you obtain segment and offset addresses from a far address of a memory location?

1075


Is it legal in c++ to overload operator++ so that it decrements a value in your class?

1049


What is the use of endl in c++?

1016


Difference between Abstraction and encapsulation in C++?

1153


What are single and multiple inheritances in c++?

1095


What's the best free c++ profiler for windows?

1078


What is diamond problem in c++?

996


Program to check whether a word is a sub-string or not of a string typed

2028


Is c++ proprietary?

1059


Explain object slicing in c++?

1058


which operator is used for performing an exponential operation a) > b) ^ c) none

1059


What are the new features that iso/ansi c++ has added to original c++ specifications?

1136


Differentiate between a pointer and a reference with respect to c++.

1243


How does c++ structure differ from c++ class?

1124


What is the c++ programming language used for?

1042