3.write the program find second largest element in an array.
class Program
{
static void Main(string[] args)
{
//Find the Second highest 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 Hieghest element is :" + array[1]);
Console.ReadLine();
}
}
Output :
Second Hieghest element is 50