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
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.
Explain what is the heap?
What is the difference between new and malloc functions?
I need a sort of an approximate strcmp routine?
What are pragmas and what are they good for?
Tell me what are bitwise shift operators?
What are the header files used in c language?
What are the advantages and disadvantages of a heap?
Which of these functions is safer to use : fgets(), gets()? Why?
What does calloc stand for?
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?
What is the use of function in c?
Give basis knowledge of web designing ...
Explain what are linked list?
What are the different categories of functions in c?