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 is atoi and atof in c?

612


FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above

618


What is clrscr ()?

633


largest Of three Number using without if condition?

1003


What is your stream meaning?

603






Should a function contain a return statement if it does not return a value?

592


What is static and auto variables in c?

562


Explain how are 16- and 32-bit numbers stored?

780


What is 02d in c?

633


How do we declare variables in c?

561


What is a structure in c language. how to initialise a structure in c?

603


Difference between constant pointer and pointer to a constant.

607


I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.

1735


What does != Mean in c?

582


What are the main characteristics of c language describe the structure of ac program?

604