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 / vinod, bangalore, india

int Second_Max(int* numbers, int Lenght)
{

int Max, Sec_Max, index;
Max = Sec_Max = numbers[0];
for(index=0; (index<Lenght) &&(Max == Sec_Max);
index++)
{
if(Max > numbers[index])
Sec_Max = numbers[index];
else
Max = numbers[index];
}
if(index == Lenght)
{
printf("Array contain simillar data and the
data is = %d \n", Max);
return false;
}


for(index =0; index < Lenght; index++)
{
if(numbers[index] > Max)
{
Sec_Max = Max;
Max = numbers[index];
}
if((numbers[index] < Max) && (numbers
[index] > Sec_Max))
{
Sec_Max = numbers[index];
}
}
return Sec_Max;
}

Is This Answer Correct ?    2 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Who was the creator of c++?

1043


How can you quickly find the number of elements stored in a static array? Why is it difficult to store linked list in an array?

975


Does std endl flush?

1032


Explain the different access specifiers for the class member in c++.

994


What is operators in c++?

1001


What is the maximum combined length of command line arguments including the space between adjacent arguments?

995


total amount of milk produced each morning and then calculates and outputs the number of cartons needed for this milk , the cost of producing the milk and the profit from producing this milk.

2573


Can we use clrscr in c++?

1079


What is array give example?

1045


What is the difference between a reference and a pointer?

1104


What is stl containers in c++?

1047


What are the advantages of using pointers in a program?

1133


What are the benefits of operator overloading?

1207


Explain the differences between private, public and protected and give examples.

1020


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

1117