Write a program that read 2o numbers in and array and
output the second largest number. Can anybody help??
Answer Posted / ada
oid SecondMax(int *a)
{
int *p = a;
int i, max, smax;
smax = max = *p++;
for(i=1;i<20;i++,p++)
{
if(*p>max)
{
smax = max;
max = *p;
}
}
if(smax!=max)
{
cout<<"The second largest number is "<<smax<<endl;
}
else
{
cout<<"There's no second largest number: all elements are
equal"<<endl;
}
}
| Is This Answer Correct ? | 2 Yes | 5 No |
Post New Answer View All Answers
Is map ordered c++?
Define the operators that can be used with a pointer.
Which programming language is best to learn first?
What are vectors used for in c++?
What is the keyword auto for?
Discuss the effects occur, after an exception thrown by a member function is unspecified by an exception specification?
Why is c++ so fast?
Can non-public members of another instance of the class be retrieved by the method of the same class?
Write a program to interchange 2 variables without using the third one.
What are destructors?
What does new do in c++?
Is c++ map a hash table?
What is a c++ vector?
What are friend functions in C++?
How many types of scopes are there in c++?