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 / rw-rwx

This might help.


max1=a[0];max2=a[1];

for(i=1;i<n;i++)
{
if(max1<a[i])
{
max2=max1;
max1=a[i];
}



if(max2==max1) max2=a[i+1];

if(max2==a[n]) { printf("All numbers are the same no second max.\n"); return 0;}


if(max2<a[i] && max1!=a[i]) max2=a[i];
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How did c++ get its name?

970


List down the guideline that should be followed while using friend function.

1005


Is swift a good first language?

1000


What are the vectors in c++?

983


What are the syntactic rules to be avoid ambiguity in multiple inheritance?

1122


Why c++ is so important?

1021


Explain the isa and hasa class relationships.

989


Write a program to show polymorphism in C++?

1078


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

987


What is c++ library?

990


What is == in programming?

972


Do you need a main function in c++?

1072


Is c++ an oop?

1026


what is COPY CONSTRUCTOR and what is it used for?

1021


Describe about storage allocation and scope of global, extern, static, local and register variables?

1197