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

Why do we use classes in programming?

1003


What are structs in c++?

991


What is this weird colon-member (" : ") syntax in the constructor?

989


What is array in c++ pdf?

1124


What does floor mean in c++?

1036


What are the storage qualifiers?

1129


How long does it take to get good at leetcode?

1140


Why is c++ so fast?

994


Do class declarations end with a semicolon? Do class method definitions?

1113


Is c++ an oop?

1048


What is the best way to declare and define global variables?

1262


What return value must conversion operators have in their declaration?

1048


Can we make any program in c++ without using any header file and what is the shortest program in c++.

1091


What are the advantages of c++ over c?

1036


Can you declare an array without a size in c++?

986