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 c program to find the largest and 2nd largest numbers from the given n numbers without using arrays
Is python a c language?
What is sizeof c?
What do you mean by Recursion Function?
What are the complete rules for header file searching?
What does c mean before a date?
When was c language developed?
how should functions be apportioned among source files?
What are the __date__ and __time__ preprocessor commands?
What is data structure in c and its types?
How to declare a variable?
why programs in c are running with out #include
What is d scanf?
Why c language?
how many errors in c explain deply