How to find Second Highest value to array

Omniitstudent
Posted by Omniitstudent under C# category on | Points: 40 | Views : 18430
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication30
{

class Program
{
static void Main(string[] args)
{


int[] arr = {52,42,36,89};

int firstmax,seconmax;
firstmax=seconmax=arr[0];
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] > firstmax)
{
seconmax = firstmax;
firstmax = arr[i];
}
else if (arr[i]>seconmax)
{
seconmax=arr[i];
}


}


Console.WriteLine(seconmax);
Console.ReadLine();

}
}
}
==================
output -- 52

--carzy code

Comments or Responses

Login to post response