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


Please Help Members By Posting Answers For Below Questions

How can a struct in c++ differs from a struct in c?

614


What are exceptions c++?

599


How do you declare A pointer to a function which receives nothing and returns nothing

726


Can a program run without main in c++?

590


What is the purpose of templates in c++?

569






Can you use the function fprintf() to display the output on the screen?

670


Discussion on error handling of C++ .

650


Why Pointers are not used in C++?

624


Briefly describe a B+ tree. What is bulk loading in it?

807


Write a program in C++ for Fibonacci series

666


What is lambda in c++?

582


write a corrected statement in c++ so that the statement will work properly. x = y = z + 3a;

1461


Write a program to show polymorphism in C++?

636


How do c++ struct differs from the c++ class?

594


Why do we use setw in c++?

651