Find the second maximum in an array?

Answers were Sorted based on User's Feedback



Find the second maximum in an array? ..

Answer / navs

if we take the array as
arr[]={1,4,7,2,10,0,6}

get the count

int count =6;
int max =arr[0];
int smax;

for (i=0;i<=count;i++)
{
if(max<arr[i])
{
smax=max;
max=max[i];
}
}

smax would give the second largest number

Is This Answer Correct ?    0 Yes 6 No

Find the second maximum in an array? ..

Answer / vili

// this deals with negative numbers as well
int getSecondMax( int* pArray, int nSize )
{
int nMax = pArray[0];
int n2ndMax = pArray[0];
for ( int i = 1; i < nSize; i++ )
{
if ( nMax < pArray[i] )
{
n2ndMax = nMax;
n2ndMax = pArray[i];
}
}
return n2ndMax;
}

Is This Answer Correct ?    6 Yes 22 No

Post New Answer

More C++ General Interview Questions

What are disadvantages of pointers?

0 Answers  


Difference between static global and global?

16 Answers   Microsoft, Symphony, Wipro,


Write a program to get the value of sin (x) using a library function , when x is given in degrees.

1 Answers  


What is the best it certification?

0 Answers  


What flag means?

0 Answers  






What are the advantages of c++? Explain

0 Answers  


Explain virtual class and friend class.

0 Answers  


What's c++ used for?

0 Answers  


How many namespaces are there in c++?

0 Answers  


Explain what are the sizes and ranges of the basic c++ data types?

0 Answers  


What is private public protected in c++?

0 Answers  


Is c++ vector a linked list?

0 Answers  


Categories