Write a program that read 2o numbers in and array and
output the second largest number. Can anybody help??
Answer Posted / mms zubeir
void main()
{
int numbers[20];
int biggest=0, secondBiggest=0;
for(int index = 0; index < 20; ++index)
{
int input;
cin>>input;
if(input == biggest)
continue;
if(input > biggest)
{
secondBiggest = biggest;
biggest = input;
}
else if(input > secondBiggest)
secondBiggest = input;
}
cout<<endl<<"Biggest : "<<biggest<<endl<<"Second
biggest : "<<secondBiggest<<endl;
getch();
}
| Is This Answer Correct ? | 6 Yes | 6 No |
Post New Answer View All Answers
What is the use of c++ programming language in real life?
What is a container class? What are the types of container classes in c++?
Differentiate between an external iterator and an internal iterator?
In what situations do you have to use initialization list rather than assignment in constructors?
How the endl and setw manipulator works?
What do manipulators do?
What are move semantics?
How would you obtain segment and offset addresses from a far address of a memory location?
What does catch(…) mean?
Why are pointers not used in c++?
Who discovered c++?
Draw a flow chart and write a program for the difference between the sum of elements with odd and even numbers. Two dimensional array.
Mention the purpose of istream class?
Using a smart pointer can we iterate through a container?
Perform addition, multiplication, subtraction of 2-D array using Operator Overloading.