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

Write a program to compute the similarity between two strings - The program should get the two strings as input - Then it will output one single number which is the percentage of similarity between the two strings

2710


What is local and global variable in c?

1142


Explain what is the difference between functions abs() and fabs()?

1114


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

1031


On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area

1075


Q.1 write a program to create binary tree 1 to 16 numbers? Q.2 write a program to creat a binary search tree for the member that is given by user?

2512


What are local static variables?

1094


What are the general description for loop statement and available loop types in c?

1078


What do you mean by scope of a variable in c?

979


Which operators cannot be overloaded a) Sizeof b) .* c) :: d) all of the above

1107


What are the 32 keywords in c?

1054


What is stack in c?

1036


Explain built-in function?

1097


write a program to reverse a every alternetive words in a string in a place. EX: Input is "this is the line of text" Output should be "shit is eht line fo text" Please any one tell me code for that.

2049


What is typedf?

1081