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 a function simple definition?
Is there any possibility to create customized header file with c programming language?
What is Dynamic memory allocation in C? Name the dynamic allocation functions.
What is a macro in c preprocessor?
What is quick sort in c?
What is the role of && operator in a program code?
Tell me the use of bit field in c language?
What is string length in c?
What is an expression?
What is c programming structure?
Write a program to print “hello world” without using semicolon?
explain what are actual arguments?
How many bytes is a struct in c?
What are reserved words?
Where register variables are stored in c?