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 are the advantages of a macro over a function?
What is the use of getch ()?
praagnovation
What is the importance of c in your views?
What is the purpose of realloc()?
Can a file other than a .h file be included with #include?
What does sizeof return c?
What is the ANSI C Standard?
Write a code to generate divisors of an integer?
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 are the functions to open and close file in c language?
Write a program to show the change in position of a cursor using c
Can a pointer be static?
why return type of main is not necessary in linux
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