29. 구조체를 이용한 카운트 알고리즘
.NET프로그래밍/C# 3.5 SP1 2009. 8. 6. 13:23 |public struct Data
{
public static int[] Num; // 원본데이터(배열이 담긴 그릇)
public static int Count; // 짝수의 개수가 담길그릇
}
public class 카운트
{
public static void Main()
{
//Data.Num = new int[] { 1, 2, 3, 4, 5 };
//for (int i = 0; i < Data.Num.Length; i++)
//{
// if (Data.Num[i] % 2 == 0)
// {
// Data.Count++;
// }
Exec();
//}
Console.WriteLine("짝수 건수: {0}", Data.Count);
}
public static void Exec()
{
Data.Num = new int[] { 1, 2, 3, 4, 5 };
for (int i = 0; i < Data.Num.Length; i++)
{
if (Data.Num[i] % 2 == 0)
{
Data.Count++;
}
}
}
}
'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글
알고리즘 - 7. 최빈값 (0) | 2009.08.06 |
---|---|
알고리즘 - 6. 가까운값(NEAR) (0) | 2009.08.06 |
28. 열거형 (0) | 2009.08.06 |
27. 문자구조체 (0) | 2009.08.06 |
26. 날짜관련구조체 (0) | 2009.08.06 |