using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[10];
int max, before_max;
Random rnd = new Random();
for (int i = 0; i < arr.Length; i++)
{
arr[i] = rnd.Next(1, 100);
Console.Write("{0} ", arr[i]);
}
// example 1
max = before_max = int.MinValue;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] > max)
{
before_max = max;
max = arr[i];
}
else if (arr[i] > before_max)
before_max = arr[i];
}
Console.WriteLine("max = {0} before_max = {1}", max, before_max);
// example 2
Array.Sort(arr);
Console.WriteLine("max = {0} before_max = {1}", arr[arr.Length - 1], arr[arr.Length - 2]);
}
}
}