C Program to find Second smallest element in the array

Get array size n and n elements of array, then find the second smallest element among those elements.

Sample Input 1:

5 5 7 9 3 1

Sample Output 1:

3

Program or Solution

				
			
					
			
				
			

Program Explanation

Initialize min and second_min with INT_MAX(INT_MAX is constant holds maximum integer value) visit every location in the array a) If the current element in array a[i] is less than min.

Then update min and second_min as, second_min = min min = a[i] b) If the current element is greater than min and less than second_min, then update second_min to store the value of current variable as second_min = arr[i] print the value stored in second_min.


Tech Events

Hackathon