find second largest element in array w/o using sorting
techniques? use onle one for loop.
Answer Posted / maxerp
int secondLargestNumber(int a[],int numberOfValues)
{
int largest=secondLargest=a[0];
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 ? | 29 Yes | 14 No |
Post New Answer View All Answers
What is queue in c?
#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }
What is #define used for in c?
Explain what are bus errors, memory faults, and core dumps?
Explain what is the benefit of using #define to declare a constant?
what is use of malloc and calloc?
What is boolean in c?
"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks
Why static variable is used in c?
which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +
Why can arithmetic operations not be performed on void pointers?
In which layer of the network datastructure format change is done
can we change the default calling convention in c if yes than how.........?
Is main is user defined function?
How to write a code for reverse of string without using string functions?