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

What is size of string in c++?

988


If you hear the cpu fan is running and the monitor power is still on, but you did not see anything show up in the monitor screen. What would you do to find out what is going wrong?

1137


How can we check whether the contents of two structure variables are same or not?

1079


Write some differences between an external iterator and an internal iterator?

1030


Explain what is class definition in c++ ?

1129


what are Access specifiers in C++ class? What are the types?

1236


Explain linear search.

1067


Explain the use of vtable.

1092


What are function prototypes?

1249


What is the difference between mutex and binary semaphore?

1247


What is the use of cmath in c++?

1077


the maximum length of a character constant can be a) 2 b) 1 c) 8

1100


What is function overloading in C++?

1433


Does c++ have string data type?

1112


Can we use this pointer inside static member function?

1076