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 process to create increment and decrement stamen in c?
I need testPalindrome and removeSpace
#include
Is fortran faster than c?
Why is main function so important?
Why is this loop always executing once?
how is the examination pattern?
What is %d used for?
Write a Program to accept different goods with the number, price and date of purchase and display them
What is an array? What the different types of arrays in c?
What is #define size in c?
Why c is called a mid level programming language?
What is a built-in function in C?
What is #pragma statements?
If errno contains a nonzero number, is there an error?
What is volatile keyword in c?