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 the difference between single charater constant and string constant?

625


What are the benefits of c language?

650


What are the different types of data structures in c?

610


What does stand for?

601


How do you search data in a data file using random access method?

839






what will be the output for the following main() { printf("hi" "hello"); }

9346


Study the following C program :call_me (myvar)int myvar;{ myvar +- 5; }main(){int myvar;myvar = 3;call_me(myvar);printf("%d ",myvar);What will be printed a) 3 b) 5 c) 8 d) symbol

669


How can a string be converted to a number?

521


What is the difference between #include

and #include “header file”?

555


What are the 5 organizational structures?

571


any restrictions have on the number of 'return' statements that may be present in a function. a) no restriction b) only 2 return statements c) only 1 return statements d) none of the above

663


Is sizeof a keyword in c?

586


What are the types of variables in c?

582


Who is the founder of c language?

688


How can I do graphics in c?

597