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
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
What is local and global variable in c?
Explain what is the difference between functions abs() and fabs()?
Should a function contain a return statement if it does not return a value?
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
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?
What are local static variables?
What are the general description for loop statement and available loop types in c?
What do you mean by scope of a variable in c?
Which operators cannot be overloaded a) Sizeof b) .* c) :: d) all of the above
What are the 32 keywords in c?
What is stack in c?
Explain built-in function?
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.
What is typedf?