2. Write a program in C# Sharp to find the second smallest element in an array.
Array List is : 10, 20, 30, 40, 50, 60
Second Smallest : 20
Output :
Second Smallest element is : 20
Second Smallest : 20
class Program
{
static void Main(string[] args)
{
//Find the Second Smallest element in a given array
int[] array = {10, 20, 30, 40, 50, 60};
int temp;
for (int i = 0; i < array.Length; i++)
{
for (int j = i+1; j < array.Length; j++)
{
if (array[i] > array[j])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
Console.WriteLine("\nSecond Smallest element is :" + array[1]);
Console.ReadLine();
}
}
Output :
Second Smallest element is : 20