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
How can a struct in c++ differs from a struct in c?
What are exceptions c++?
How do you declare A pointer to a function which receives nothing and returns nothing
Can a program run without main in c++?
What is the purpose of templates in c++?
Can you use the function fprintf() to display the output on the screen?
Discussion on error handling of C++ .
Why Pointers are not used in C++?
Briefly describe a B+ tree. What is bulk loading in it?
Write a program in C++ for Fibonacci series
What is lambda in c++?
write a corrected statement in c++ so that the statement will work properly. x = y = z + 3a;
Write a program to show polymorphism in C++?
How do c++ struct differs from the c++ class?
Why do we use setw in c++?