"find second max element in array in 1 iteration" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "find second max element in array in 1 iteration" answered properly. Developers are finding an appropriate answer about find second max element in array in 1 iteration related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like find second max element in array in 1 iteration. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on find second max element in array in 1 iteration.
find second max element in array in 1 iteration
/**
* C program to find second largest number in an array
*/
#include <stdio.h>
#include <limits.h> // For INT_MIN
#define MAX_SIZE 1000 // Maximum array size
int main()
{
int arr[MAX_SIZE], size, i;
int max1, max2;
/* Input size of the array */
printf("Enter size of the array (1-1000): ");
scanf("%d", &size);
/* Input array elements */
printf("Enter elements in the array: ");
for(i=0; i<size; i++)
{
scanf("%d", &arr[i]);
}
max1 = max2 = INT_MIN;
/*
* Check for first largest and second
*/
for(i=0; i<size; i++)
{
if(arr[i] > max1)
{
/*
* If current element of the array is first largest
* then make current max as second max
* and then max as current array element
*/
max2 = max1;
max1 = arr[i];
}
else if(arr[i] > max2 && arr[i] < max1)
{
/*
* If current array element is less than first largest
* but is greater than second largest then make it
* second largest
*/
max2 = arr[i];
}
}
printf("First largest = %d\n", max1);
printf("Second largest = %d", max2);
return 0;
}
Source: codeforwin.org
All those coders who are working on the Whatever based application and are stuck on find second max element in array in 1 iteration can get a collection of related answers to their query. Programmers need to enter their query on find second max element in array in 1 iteration related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about find second max element in array in 1 iteration for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of find second max element in array in 1 iteration while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "find second max element in array in 1 iteration". Visit this developer's friendly online web community, CodeProZone, and get your queries like find second max element in array in 1 iteration resolved professionally and stay updated to the latest Whatever updates.