find second largest element in array w/o using sorting
techniques? use onle one for loop.

Answer Posted / athul

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],n,i,big,big2;
cout<<"Enter the limit\n";
cin>>n;
cout<<"Enter the arrays\n";
for(i=0;i<n;i++)
{
cin>>a[i];
big=a[0];
}
for(i=0;i<n;i++)
{
if(big<a[i])
{
big2=big;
big=a[i];
}
else if(big2<a[i])
{
big2=a[i];
}
}
cout<<"The second biggest number is "<<big2<<endl;
getch();
}

Is This Answer Correct ?    6 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

One of the Institutes contains 5 student groups. Every group contains 4 students. Institute wants to store student group’s details in array. Group should contain group member’s details (name and registration number and age), project name, and mark of the group.

2152


Explain what is the heap?

616


What is the difference between new and malloc functions?

572


I need a sort of an approximate strcmp routine?

654


What are pragmas and what are they good for?

567






Tell me what are bitwise shift operators?

650


What are the header files used in c language?

578


What are the advantages and disadvantages of a heap?

697


Which of these functions is safer to use : fgets(), gets()? Why?

629


What does calloc stand for?

643


How to write a program for machine which is connected with server for that server automatically wants to catch the time for user of that machine?

1581


What is the use of function in c?

702


Give basis knowledge of web designing ...

1567


Explain what are linked list?

615


What are the different categories of functions in c?

639