Write a program to find the second smallest element in a given array of integers.
Write a program to find the second smallest element in a given array of integers.
700
21-Apr-2023
Updated on 22-Apr-2023
Aryan Kumar
22-Apr-2023In this program, we first ask the user to input the number of elements in the array and then we take the input of the elements. We then sort the array in ascending order using a simple bubble sort algorithm. Finally, we find the second smallest element by looping through the array and checking for the element which is not equal to the first element of the array (which is the smallest element).
Note: This program assumes that there are at least two distinct elements in the array. If all elements are the same, it will output an incorrect result.
Krishnapriya Rajeev
21-Apr-2023Given below is a sample program to find the second smallest number in an array.