find second largest element in array w/o using sorting
techniques? use onle one for loop.
Answer Posted / anand
Initializing second_largest to max negative number will ensure for all (+ve and -ve range of values).
int secondLargestNumber(int arr[],int numberOfValues)
{
int largest=arr[0];
int second_largest= -(2^(sizeof(int)*8 -1));
int i;
for(i=1;i<numberOfValues;i++)
{
if(a[i]>largest)
{
secondLargest=largest;
largest=a[i];
}
if(a[i]>secondLargest && a[i]<largest)
secondLargest=a[i];
}
return secondLargest;
}
Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
What does 2n 4c mean?
What is wrong with this program statement?
What is volatile, register definition in C
Explain the difference between null pointer and void pointer.
What is pre-emptive data structure and explain it with example?
What does d mean?
What is the difference between text and binary modes?
What is cohesion and coupling in c?
What is the value of uninitialized variable in c?
What is the right way to use errno?
Why & is used in c?
WHICH TYPE OF JOBS WE GET BY WRITING GROUPS .WHEN THE EXAMS CONDUCTED IS THIS EXAMS ARE CONDUCTED EVERY YEAR OR NOT.PLS TELL ME THE ANSWER
What is the use of sizeof () in c?
What does a pointer variable always consist of?
What is pivot in c?