Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- printf("Array size : ");
- int arraySize;
- scanf("%d", &arraySize);
- int array[arraySize];
- for(int i=0; i<arraySize; i++)
- {v c
- printf("Enter element %d : ", i);
- scanf("%d", &array[i]);
- }
- int scndMaxElement = find_scnd_max(array, arraySize);
- printf("The 2nd max element is : %d", scndMaxElement);
- }
- int find_scnd_max(int array[], int arraySize)
- {
- int maxElement = array[0];
- int scndMaxElement = array[0];
- for(int i=1; i<arraySize; i++)
- {
- if(array[i]>maxElement)
- {
- scndMaxElement = maxElement;
- maxElement = array[i];
- }
- }
- return scndMaxElement;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement