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

int sec_max(int a[])
{
if(a[0]>a[1])
{
max=a[0]
sec_max=a[1]
}
else
{
max=a[1]
sec_max=a[0]
}
for(i=1;i<n-1;i++)
{
if (a[i]>sec_max && a[i]< max)
{
sec_max=a[i];
}
else if(a[i]>max)
{
sec_max=max;
max=a[i];
}
return sec_max;
}

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Should you pass exceptions by value or by reference?

1137


What is #include sstream?

1076


Why c++ does not have finally?

1090


Explain terminate() and unexpected() function?

1110


What is the difference between a pointer and a link in c ++?

1057


How do you generate a random number in c++?

1103


Eplain extern keyword?

1036


How would you use the functions memcpy(), memset(), memmove()?

1098


What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?

1184


What is c++ runtime?

1115


Does c++ have foreach?

1071


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

1068


Are vectors passed by reference c++?

997


What are activex and ole?

1063


why is iostream::eof inside a loop condition considered wrong?

1061