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 malloc return c?
What is ctrl c called?
What is the use of header files?
Write a program for finding factorial of a number.
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.
what is the height of tree if leaf node is at level 3. please explain
HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????
What is const volatile variable in c?
What are the types of operators in c?
How do I use strcmp?
What are structure members?
What are the advantages and disadvantages of c language?
If errno contains a nonzero number, is there an error?
Can you apply link and association interchangeably?
What is dynamic memory allocation?