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

what are the advantages of a macro over a function?

650


What is the use of getch ()?

640


praagnovation

1780


What is the importance of c in your views?

599


What is the purpose of realloc()?

674






Can a file other than a .h file be included with #include?

688


What does sizeof return c?

610


What is the ANSI C Standard?

782


Write a code to generate divisors of an integer?

645


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

1962


What are the functions to open and close file in c language?

732


Write a program to show the change in position of a cursor using c

585


Can a pointer be static?

627


why return type of main is not necessary in linux

1708


a construct the"else" part of "if" statement contains anoth "if else" statement is called a) if-else b) else-if-else c) if-else-if-else d) chain if/if-else-if

707