Blog Content

  • 06.C# - 알고리즘 : 최빈값 (가장 많이 나타낸 값)

    Category C# on 2009. 8. 6. 21:13

    최빈값(가장 많이 나타낸 값)을 구하는 예제입니다. //최빈값(MODE) : 가장 많이 나타난 값 // -> 데이터의 인덱스(0~100점)의 카운터(COUNT)값의 최대값(MAX) using System; public class 최빈값 { static void Main(string[] args) { int[] score = { 6, 3, 2, 2, 2, 4, 4 }; int mode = 0; //최빈값이 담길 그릇 int[] index = new int[7]; int max = Int32.MinValue; for (int i = 0; i < score.Length; i++) { index[score[i]]++; //count } for (int i = 0; i < index.Length; i++) { i..

    Read more
  • 05.C# - 알고리즘 : 가까운 값 구하기

    Category C# on 2009. 8. 6. 20:26

    변수에 저장된 값과 가장 가까운 배열에 선언된 값을 찾는 예제 입니다. using System; public class 가까운값 { public static void Main(string[] args) { //[1] Input int[] data = { 10, 20, 30, 26, 27, 17 }; int target = 25; // traget과 가까운 값 int near = 0; //가까운값 : 27 int min = Int32.MaxValue; //[2] Process for (int i = 0; i < data.Length; i++) { if (Abs(data[i] - target) < min) { min = Abs(data[i] - target); //최소값 알고리즘 near = data[i];..

    Read more
  • 04.C# - 알고리즘 : 최소값

    Category C# on 2009. 8. 5. 23:38

    using System; public class 최소값 { public static void Main() { //[1]Init int min = Int32.MaxValue;▼ //[2] Input int[] data = { -2, -5, -3, -7, -1 }; //[3] Process : MAX for (int i = 0; i data[i]) { min = data[i]; } } //[4] Output Console.WriteLine("최소값 : {0}", min); //[5] Dispose min = 0; } } ▼ 정수형중 가장 큰 값으로 초기화 했습니다. 참고강좌(19장-최대값)

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

    Category C# on 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 ▶ 해당 범위 내에서 가장 작은 값으로 초기화 선언 (정수형 데이터중 가장 작은 값으로 초기화)

    Read more
  • 02.C# - 알고리즘 : 평균

    Category C# on 2009. 8. 5. 20:51

    using System; public class 평균 { public static void Main(string[] args) { //[1] Input int[] data = { 50, 65, 78, 90, 95 }; int count = 0; //평균을 나누기 위한 변수 int sum = 0; // 합계 값을 저장하는 변수 double avg = 0.0; //평균이 저장될 변수 //[2] Process : AVG for (int i = 0; i = 80 && data[i]

    Read more
  • 01.C# - 알고리즘 : 합계

    Category C# on 2009. 8. 5. 20:20

    합계 알고리즘 예제 입니다. using System; public class 합계 { public static void Main(string[] args) { //[1] Input : 5명의 국어 점수 int[] score = { 75, 50, 37, 90, 95 }; int sum = 0; //[2] Process : SUM foreach (int item in score) { if (item >= 80) { sum += item; } } //[3] Output Console.WriteLine("5명의 점수중 80점 이상의 총점: {0} 이고 인원은 {1}명", sum, score.Length); } }

    Read more
이전 1 다음