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

What are the advantages of using a pointer? Define the operators that can be used with a pointer.

1074


Explain about templates of C++.

1198


what are the decision making statements in C++? Explain if statement with an example?

1144


How would you find out if a linked-list is a cycle or not?

1054


How much maximum can you allocate in a single call to malloc()?

1150


What is meant by iomanip in c++?

1290


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

1114


Why do we use vector in c++?

1122


What do manipulators do?

1065


How can we access protected and private members of a class?

1162


Do you know what are the new features that iso/ansi c++ has added to original c++ specifications?

1185


Which of the following is evaluated first: a) && b) || c) !

2417


What are the differences between new and malloc?

1199


What are the rules for naming an identifier?

1121


Define Virtual function in C++.

1148