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

What is the difference between a type-specific template friend class and a general template friend class?

656


What are the different types of polymorphism in c++?

699


What is using namespace std in cpp?

638


What is the difference between public, private, and protected access?

692


What does new in c++ do?

650






Is python written in c or c++?

734


What is ios in c++?

747


What is c++ manipulator?

636


Can c++ do everything c can?

693


What is flag in computer?

683


What is a class definition?

704


What is low level language in simple words?

641


Can user-defined object be declared as static data member of another class?

632


What is meant by a delegate?

711


Explain public, protected, private in c++?

658