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
What are friend classes? What are advantages of using friend classes?
What is a block in c++?
What is a pointer with example?
How do you traverse a btree in backward in-order?
How does code-bloating occur in c++?
What do you mean by stack unwinding in c++?
Is nan a c++?
Why is that unsafe to deal locate the memory using free( ) if it has been allocated using new?
How do you declare A pointer to function which receives an int pointer and returns a float pointer
What is a v-table?
Name four predefined macros.
Is c++ low level?
Explain how functions are classified in C++ ?
How does c++ sort work?
What is new in c++?