.NET프로그래밍/C# 3.5 SP1

알고리즘 - 5. 최소값(MIN)

holland14 2009. 8. 5. 14:29

using System;

public class 최소값
{
    public static void Main()
    {
        //[1] Initialize
        int min = Int32.MaxValue; // 정수형 중 가장 큰 값으로 초기화
        //[2] Input
        int[] data = { -2, -5, -3, -7, -1 };
        //[3] Process : MIN
        for (int i = 0; i < data.Length; i++)
        {
            if (data[i] < min)
            {
                min = data[i]; // MIN
            }
        }
        //[4] Output
        Console.WriteLine("최소값 : {0}", min); // -7
        //[5] Dispose
        min = 0;
    }
}