Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

find second largest element in array w/o using sorting
techniques? use onle one for loop.

Answer Posted / anand

Initializing second_largest to max negative number will ensure for all (+ve and -ve range of values).

int secondLargestNumber(int arr[],int numberOfValues)
{
int largest=arr[0];
int second_largest= -(2^(sizeof(int)*8 -1));
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 ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is getch () for?

1149


Tell me when would you use a pointer to a function?

1011


What is the use of define in c?

1001


What does it mean when the linker says that _end is undefined?

1040


How can I find out the size of a file, prior to reading it in?

1100


In which header file is the null macro defined?

1302


What is a buffer in c?

946


difference between object file and executable file

6641


how to build a exercise findig min number of e heap with list imlemented?

2017


Explain what is the benefit of using const for declaring constants?

967


Explain what is the purpose of "extern" keyword in a function declaration?

1029


What are the differences between Structures and Arrays?

1130


Can variables be declared anywhere in c?

1036


What is include directive in c?

1092


Can include files be nested?

1059