find second largest element in array w/o using sorting
techniques? use onle one for loop.

Answer Posted / alam cse-35 bangladesh univers

#include<iostream>
using namespace std;
int main()
{
int i,a[]={121,104,105,205,6,25,80,77,120},max=0,second_max=0;
for(i=0;i<=8;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
for(i=0;i<=8;i++)
{
if(a[i]!=max)
{
if(a[i]>second_max)
{
second_max=a[i];
}
}
}

cout<<"Second Highest Value:"<<second_max<<endl;
cout<<"Maximum Value:"<<max;
return 0;
}

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is malloc return c?

596


What is ctrl c called?

588


What is the use of header files?

599


Write a program for finding factorial of a number.

629


You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.

1778






what is the height of tree if leaf node is at level 3. please explain

1595


HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????

2263


What is const volatile variable in c?

572


What are the types of operators in c?

609


How do I use strcmp?

634


What are structure members?

590


What are the advantages and disadvantages of c language?

556


If errno contains a nonzero number, is there an error?

798


Can you apply link and association interchangeably?

669


What is dynamic memory allocation?

804