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
Explain what is operator promotion?
Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
differentiate built-in functions and user – defined functions.
Write a program to print "hello world" without using a semicolon?
Why is c used in embedded systems?
What is the purpose of realloc()?
What is #include called?
How many bytes is a struct in c?
Why cant I open a file by its explicit path?
What is the difference between variable declaration and variable definition in c?
What is null character in c?
How can I implement a delay, or time a users response, with sub-second resolution?
What is a stream in c programming?
how to capitalise first letter of each word in a given string?
Explain why c is faster than c++?