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 do you mean by global variables?

572


If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?

1008


What is the most powerful coding language?

618


Suppose that data is an array of 1000 integers. Write a single function call that will sort the 100 elements data [222] through data [321].

962


How can a called function determine the number of arguments that have been passed to it?

658






How a new operator differs from the operator new?

625


How do you instruct your compiler to print the contents of the intermediate file showing the effects of the preprocessor?

584


What does new in c++ do?

568


Are c and c++ similar?

588


What does std mean in c++?

583


Is swift better than c++?

540


Explain polymorphism?

586


What is the full form of india?

568


Ask to write virtual base class code?

2149


Explain operator overloading.

604