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 is getch () for?
Tell me when would you use a pointer to a function?
What is the use of define in c?
What does it mean when the linker says that _end is undefined?
How can I find out the size of a file, prior to reading it in?
In which header file is the null macro defined?
What is a buffer in c?
difference between object file and executable file
how to build a exercise findig min number of e heap with list imlemented?
Explain what is the benefit of using const for declaring constants?
Explain what is the purpose of "extern" keyword in a function declaration?
What are the differences between Structures and Arrays?
Can variables be declared anywhere in c?
What is include directive in c?
Can include files be nested?