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 c++ vector a linked list?

548


Why the usage of pointers in C++ is not recommended ?

890


What are the steps in the development cycle?

613


What is c++ & why it is used?

588


What is rtti in c++?

625






Will a catch statement catch a derived exception if it is looking for the base class?

556


Write a program to find the Fibonacci series recursively.

601


Which software is used for c++ programming?

612


Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

787


What does flush do?

557


Write about the members that a derived class can add?

565


Give the difference between the type casting and automatic type conversion. Also tell a suitable C++ code to illustrate both.

628


What are the differences between malloc() and calloc()?

611


Define what is constructor?

580


Is c++ faster than c?

592