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
When would you use a pointer to a function?
List a few unconditional control statement in c.
Differentiate between null and void pointers.
What does d mean?
Explain how do you convert strings to numbers in c?
How does #define work?
c program to compute AREA under integral
Why is #define used?
What is the difference between if else and switchstatement
The statement, int(*x[]) () what does in indicate?
an expression contains relational operators, assignment operators, and arithmatic operstors. In the absence of parentheses, they will be evaluated in which of the following order a) assignment, relational, arithematic b) arithematic, relational, assignment c) relational, arithematic, assignment d) assignment, arithematic, relational
int far *near * p; means
What is an endless loop?
What is fflush() function?
i got 75% in all semester am i eligible for your company