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


Please Help Members By Posting Answers For Below Questions

Explain what is the most efficient way to store flag values?

692


What is main function in c?

543


Sir i need notes for structure,functions,pointers in c language can you help me please

1941


Explain what are preprocessor directives?

621


Can we declare variable anywhere in c?

533






What is the purpose of ftell?

595


Do you have any idea how to compare array with pointer in c?

597


what value is returned to operating system after program execution?

1595


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); } }

1953


What is a lookup table in c?

622


Why does everyone say not to use gets?

603


What is c definition?

737


Which driver is a pure java driver

984


Which built-in library function can be used to match a patter from the string?

735


What are the disadvantages of external storage class?

584