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
What is the difference between single charater constant and string constant?
What are the benefits of c language?
What are the different types of data structures in c?
What does stand for?
How do you search data in a data file using random access method?
what will be the output for the following main() { printf("hi" "hello"); }
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
How can a string be converted to a number?
What is the difference between #include
What are the 5 organizational structures?
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
Is sizeof a keyword in c?
What are the types of variables in c?
Who is the founder of c language?
How can I do graphics in c?