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++ array?

557


By using c++ with an example describe linked list?

607


What is the sequence of destruction of local objects?

560


Can create new c++ operators?

576


Is c++ a low level language?

519






Can comments be nested?

632


Which compiler does turbo c++ use?

610


Write bites in Turbo c++ Header ("Include") Files.

690


How should runtime errors be handled in c++?

617


What is null c++?

590


What is c++ stringstream?

612


Define friend function.

574


. If employee B is the boss of A and C is the boss of B and D is the boss of C and E is the boss of D. Then write a program using the Database such that if an employee name is Asked to Display it also display his bosses with his name. For eg. If C is displayed it should also display D and E with C?

2764


How does work in c++?

600


Differentiate between an external iterator and an internal iterator? What is the advantage of an external iterator.

621