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


Please Help Members By Posting Answers For Below Questions

What is c++ library?

688


When does a name clash occur in c++?

806


Does c++ support multilevel and multiple inheritances?

636


Name the debugging methods that are used to solve problems?

664


How do you clear a map in c++?

684






Why is null pointer used?

787


What is wrapper class in c++?

709


Name the implicit member functions of a class.

700


Differentiate between an inspector and a mutator ?

790


What is a local reference?

780


There are 100 students in a class. The management keep information in two tables. Those two tables are given like Roll no Name Age 001 ABC 15 002 XYZ 14 and Roll No Subject Marks 001 Math 75 001 Physics 55 002 Math 68 001 Hindi 69 They want the information like this Roll No Name Hindi Physics Math Total 001 ABC 69 55 75 199 002 XYZ 68 74 84 226 And Roll No Suject Highest 001 Math 98 007 Physics 84 021 Hindi 74 All 275 All information is kept in structure in main memory. You have to find last two tables.

2622


What are smart pointers?

778


Define upcasting.

681


What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?

774


Why do we use templates?

698