Find the second maximum in an array?
Answers were Sorted based on User's Feedback
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 |
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 |
What is c++ similar to?
Show the application of a dynamic array with the help of an example.
What would happen on forgetting [], while deallocating an array through new?
Which uses less memory? a) struct astruct { int x; float y; int v; }; b) union aunion { int x; float v; }; c) char array[10];
Should a constructor be public or private?
Tell me what are static member functions?
What is the best way to declare and define global variables?
How do we balance an AVL Tree in C++?
How do you flush a buffer in c++?
Given a simple program designed to take inputs of integers from 1-1000 and to output the factorial value of that number, how would you test this program? You do not have access to the code. Please be as specific as possible.
What are proxy objects?
When should we use multiple inheritance?