C#

03.C# - 알고리즘 : 최대값

Godffs 2009. 8. 5. 23:30
반응형
최대값 구하는 예제입니다.

              using System;

              public class 최대값
              {
                  public static void Main()
                  {
                      //[1] Input
                      int max = Int32.MinValue; ▶(설명)
                      int[] data = { 2, 5, 3, 7, 1 };
       
                      //[2] Process : MAX
                      for (int i = 0; i < data.Length; i++)
                      {
                          if(max < data[i])
                          {
                              max = data[i];
                          }
                      }

                      //[3] Output       
                      Console.WriteLine("최대값 : {0}", max); ;
                  }   
              }


int max = Int32.MinValue
해당 범위 내에서 가장 작은 값으로 초기화 선언
                 (정수형 데이터중 가장 작은 값으로 초기화)
반응형