Pages

Saturday, March 16, 2013

C#: How to find minimum value from an array of integers?

  public void MinimumValInt()
        {
            int[] intArray = new int[7] { 10,4,5,1,7,15,12};
            int minVal = intArray[0];

            for (int i = 1; i < intArray.Length; i++)
            {
                if (intArray[i] < minVal)
                {
                    minVal = intArray[i];
                }
            }
            Console.WriteLine("Minimum value= "+minVal);
        }


Output: Minimum value=1

1 comment: