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
Explain what is the most efficient way to store flag values?
What is main function in c?
Sir i need notes for structure,functions,pointers in c language can you help me please
Explain what are preprocessor directives?
Can we declare variable anywhere in c?
What is the purpose of ftell?
Do you have any idea how to compare array with pointer in c?
what value is returned to operating system after program execution?
What is the purpose of the following code? Is there any problem with the code? void send(int count, short *to, short *from) { /* count > 0 assumed */ register n = (count + 7) / 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while (--n > 0); } }
What is a lookup table in c?
Why does everyone say not to use gets?
What is c definition?
Which driver is a pure java driver
Which built-in library function can be used to match a patter from the string?
What are the disadvantages of external storage class?