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
Explain binary search.
What is the function of I/O library in C++ ?
What are arrays c++?
State the difference between delete and delete[].
What is namespace & why it is used in c++?
What is c++ hiding?
Discuss the possibilities related to the termination of a program before entering the mainq method?
What is the difference between #import and #include?
How to tokenize a string in c++?
What is the protected keyword used for?
Differentiate between a constructor and a method in C++.
What is a storage class? Mention the storage classes in c++.
Describe protected access specifiers?
What is the precedence when there is a global variable and a local variable in the program with the same name?
What do you mean by function pointer?