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?

Answers were Sorted based on User's Feedback



Find the second maximum in an array? ..

Answer / navs

if we take the array as
arr[]={1,4,7,2,10,0,6}

get the count

int count =6;
int max =arr[0];
int smax;

for (i=0;i<=count;i++)
{
if(max<arr[i])
{
smax=max;
max=max[i];
}
}

smax would give the second largest number

Is This Answer Correct ?    0 Yes 6 No

Find the second maximum in an array? ..

Answer / vili

// this deals with negative numbers as well
int getSecondMax( int* pArray, int nSize )
{
int nMax = pArray[0];
int n2ndMax = pArray[0];
for ( int i = 1; i < nSize; i++ )
{
if ( nMax < pArray[i] )
{
n2ndMax = nMax;
n2ndMax = pArray[i];
}
}
return n2ndMax;
}

Is This Answer Correct ?    6 Yes 22 No

Post New Answer

More C++ General Interview Questions

What is the use of 'this' pointer?

0 Answers   Fidelity,


Why is c++ a mid-level programming language?

0 Answers  


Which is best ide for c++?

0 Answers  


Keyword mean in declaration?

0 Answers  


What are the three forms of cin.get() and what are their differences?

0 Answers  


Can I uninstall microsoft c++ redistributable?

0 Answers  


Explain about Garbage Collector?

0 Answers  


Which should be more useful: the protected and public virtuals?

0 Answers  


Which software is best for c++ programming?

0 Answers  


What is Object Oriented programming.what is the difference between C++ and C?

8 Answers   Infosys,


What is lambda expression c++?

0 Answers  


Evaulate: 22%5 a) 2 b) 4 c) 0

0 Answers  


Categories