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
Is there any possibility to create customized header file with c programming language?
How do I read the arrow keys? What about function keys?
Are the variables argc and argv are local to main?
Write a program to print "hello world" without using a semicolon?
What is the process to create increment and decrement stamen in c?
Write a programme using structure that create a record of students. The user allow to add a record and delete a record and also show the records in ascending order.
a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list
What is a newline escape sequence?
What is function and its example?
Why is c not oop?
All technical questions
What is "Duff's Device"?
What is type qualifiers?
Place the #include statement must be written in the program?
what is the format specifier for printing a pointer value?