Find the second maximum in an array?

Answer Posted / foreverkushal

int SecondMax(int *Array, int ACount)
{
int Fm = 0, Sm = 0;
for (int i = 0; i < ACount; i++)
{
if (Array[i] > Sm)
{
if (Array[i] < Fm) Sm = Array[i];
else
{
Sm = Fm;
Fm = Array[i];
}
}
}
return Sm;
}

Is This Answer Correct ?    31 Yes 22 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is linux written in c or c++?

535


Write a program using display() function which takes two arguments.

594


What is pointer to member?

589


What is the most powerful coding language?

597


Am studying basic c++ programming, have been given the following assignment. Design a linear program to calculate the maximum stress a material can withstand given a force and a diameter of a circle. To find the required area pi should be defined. Have most of the program sorted out but am at a loss as to how to show the calculations required. Can anyone help?

1720






Is java as fast as c++?

585


What is function prototyping?

602


What is the main purpose of c++?

524


How does atoi function work?

606


How to allocate memory dynamically for a reference?

532


Explain mutable storage class specifier.

612


Define macro.

566


Is c++ free?

567


What is a lambda function c++?

538


Can recursive program be written in C++?

619