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 are multiple inheritances (virtual inheritance)?

775


Who was the creator of c++?

753


Write a C++ Program to check whether a number is prime number or not?

840


Why c++ is faster than java?

797


What is istream c++?

805






How can a struct in c++ differs from a struct in c?

790


Is string an object in c++?

831


Can static member variables be private?

817


Snake Game: This is normal snake game which you can find in most of the mobiles. You can develop it in Java, C/C++, C# or what ever language you know.

2749


What is setf in c++?

809


What is operators in c++?

763


What is a tree in c++?

716


Of the numbers 12 23 9 28 which would be at the top of a properly implemented maxheap a) 28 b) 9 c) Any of them could be

1151


Can there be at least some solution to determine the number of arguments passed to a variable argument list function?

769


What is meant by forward referencing and when should it be used?

742