Find the second maximum in an array?

Answer Posted / rw-rwx

This might help.


max1=a[0];max2=a[1];

for(i=1;i<n;i++)
{
if(max1<a[i])
{
max2=max1;
max1=a[i];
}



if(max2==max1) max2=a[i+1];

if(max2==a[n]) { printf("All numbers are the same no second max.\n"); return 0;}


if(max2<a[i] && max1!=a[i]) max2=a[i];
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can I learn c++ without knowing c?

780


What is the latest c++ standard?

866


Is it possible for the objects to read and write themselves?

847


How can you say that a template is better than a base class?

767


What are the different types of comments allowed in c++?

756






What is ios in c++?

879


What are the classes in c++?

816


what Is DCS ? what i will get benefit when i did?

2022


Write a Program for dynamically intialize a 2 dimentional array. Eg:5x20, accept strings and check for vowels and display the no.finally free the space allocated .

902


What does new in c++ do?

730


What is binary object model?

755


Explain the concept of friend function in c++?

807


What is the maximum value of a unsigned char a) 255 b) 256 c) 128

832


What are the unique features of C++.

757


Explain the uses oof nested class?

852