# Find the Second Smallest And Largest Element in An Array

This is an array program using c. In which we try to find the second smallest number and second largest number in array
First we have to create an array and input some element from user. then we will sort in ascending order or descending order.

``````ALGORITHM:-

step 1 : Start
step 2 : Enter size of array
step 3 : Enter element in the array
step 4 : Sort the array in ascending or descending order
step 5 : Now there is index[1] is the second smallest number and
step 6 : index[n-2] is the second largest number
step 7 : Display the both (second smallest and largest) number
step 8 : Stop execution
``````

``````PROGRAM CODE:-

#include<stdio.h>
#include<conio.h>

int main() {
int a[50];
int i, j, temp, n ;
printf("Enter the size of array : n");
scanf("%d", &n);
printf("Enter Element in array: n");
for (j = 0; j < n; j++) {
scanf("%d", &a[j]);
}
//Sorting array using bubble sorting in ascending order
for (j = 0; j < n; j++) {
for (i = j + 1; i < n; i++) {
if (a[j] > a[i]) {
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
printf("The second smallest number is: %dn", a[1]);
printf("The second largest  number is: %d", a[n-2]);

getch();
}``````

``````OUTPUT:-

Enter the length of the array: 5
Enter element of the array:
5
1
9
5
4

The second smallest number is: 4
The second largest  number is: 5``````

``````SIMILAR POSTS:-

C Program To find the second smallest number from an array
C Program to find the second largest number from an array
How to find out the second largest and smallest element from an array using c
find the second largest number using C Programming ``````