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?

1084


the first character in the variable name must be an a) special symbol b) number c) alphabet

1150


how to access grid view row?

2283


List the special characteristics of constructor.

1219


What is difference between class and function?

1152


What is a linked list in c++?

1106


Explain the difference between overloading and overriding?

1196


Write a program to concatenate two strings.

1146


Is swift faster than go?

1138


In a function declaration, what does extern mean?

1116


Which ide is best for c++?

1089


what does the following statement mean? int (*a)[4]

1136


Is c++ map a hash table?

1077


What is an arraylist c++?

1271


What are the two types of comments?

1048