블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

Category

Recent Post

Recent Comment

Archive

'.Net Project/.Net C#'에 해당되는 글 69

  1. 2009.08.05 13장 알고리즘(Algorithm)의 이해
  2. 2009.08.05 12장 Consoal Array
  3. 2009.08.05 11장 컬렉션 반복
  4. 2009.08.04 10장 비트연산자
2009. 8. 5. 12:19 .Net Project/.Net C#
반응형

1.합계 SUM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algorithm
{
    public class sum
    {
        public static void Main()
        {
            // 1. Input : 5명의 국어 점수
            int[] score = { 100, 75, 37, 50, 95, 90 };
            int sum = 0;     

            // 2. Process : SUM
            for (int i = 0; i < score.Length; i++)
            {
                if (score[i]>=80)
                {
                    sum += score[i]; //sum
                }               
            }     
            foreach문 사용하여 출력
            foreach (var item in score)
            {
                if (item >= 80)
                {
                    sum += item;
                }
            }
           
            // 3. Output
              Console.WriteLine("5명의 점수 중 80점 이상의 총점 : {0}", sum);
              Console.WriteLine("5명의 점수 중 80점 이상의 총점 :    
                                      {1}",score.Length,sum);
              Console.Write("{0}", sum);
        }           
    }   
}

2.카운터
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algorithm
{
    public class count
    {
        public static void Main()
        {
            //1.input
            int[] data = { 10, 9, 4, 7, 6, 5 };
            int count = 0; //카운터 저장

            //2.process
          
            for (int i = 0; i < data.Length; i++)
            {
                if (data[i] % 2 == 0)
                {
                    count++;
                }
               
            }
            //3.Output
            Console.WriteLine("짝수의 건수 : {0}",count); //3
            
        }
    }
}

3.평균
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algorithm
{
     public class Average
     {
         public static void Main()
         {
             //1.Input
             int[] date = { 50, 65, 78, 90, 95 };
             int count = 0;
             double avg = 0.0; //평균이 저장될 변수
             int sum = 0;

             //2.Process
             for (int i = 0; i < date.Length; i++)
             {
                 if (date[i] >= 80 && date[i] <= 95)
                 {
                     sum += date[i];
                     count++;                    

                 }
                  
             }
             avg = sum / (double)count; //캐스팅(형식변환) 필요 : 3 -> 3.0

             //3.Output
                 Console.WriteLine
                 ("80점 이상 95점 이하인 자료의 평균 : {0}", avg); // 92.5

         }
     }
}
4.최대값
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algorithm
{
    public class Max
    {
        public static void Main()
        {
            //1. Init
            //int max = 1; //해당 범위내에서 가장 작은 값으로 초기화
            int max = Int32.MinValue;
        
            //2. Input
            int[] data = { 2, 5, 3, 7, 1 };
           
            //3. Process : Max
            for (int i = 0; i < data.Length ; i++)
            {
                if(data[i] > max)
                {
                    max = data[i];
                }
                
            }          
            
            //4. Output
            Console.WriteLine("최댓값 : {0}", max); //7    
            }        
    }
}
5.최소값
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algorithm
{
    public class Min
    {
        public static void Main()
        {
            int min = Int32.MaxValue;

            //1. Input
            int[] data = { 2, 5, 3, 7, 1 };

            //2. Process : Min
            for (int i = 0; i < data.Length; i++)
            {
                if (data[i] < min)
                {
                    min = data[i];
                }

            }
            //3. Output
            Console.WriteLine("최소값 : {0}", min); //7           
        }
   }
}

6. 가까운값
//가까운 값 : 차이값의 절대값의 최소값
using System;

public class 가까운값
{
    public static void Main()
    {
        //1.input
        int[] data = { 10, 20, 30, 27, 17 };
       
        int target = 25; //target과 가까운 값
        int near = 0;
        int min = Int32.MaxValue; // 차이값의 절대값의 최소값
        //2.process
        for (int i = 0; i < data.Length; i++)
        {
            if (Abs(data[i] - target) < min)
            {
              //min=Math.Abs(data[i]-target); 다른방식
               min = Abs(data[i]-target); //최소값
               near = data[i];
            }         

        }       
        //3.output
        Console.WriteLine("{0}와 가장 가까운 값 : {1}",target, near);
    }

    private static int Abs(int p) 함수호출 후
    {
        return (p < 0) ? -p : p; 삼항연산자를 통하여 출력
    }

}

7. 최빈값
//최빈값 : 가장 많이 나타난 값
// -> 데이터의 인덱스 (0점 ~100)의 카운터(Count)값의 최대점(MAX)

using System;

public class 최빈값
{
    public static void Main()
    {
        //1.input
        int[] score = { 1, 3, 4, 3, 5 }; //0부터 10까지 중에서 
        
        //1-1 0~5까지 배열 생성 -> 인덱스의 카운터 구하기 위해서  

        int[] index = new int[5+1];
        int max = Int32.MinValue;

        int mode = 0; //최빈값이 담길 그릇
        //int count = 0;
        //2.process

        for (int i = 0; i < score.Length; i++)
   {
                index[score[i]]++; //count알고리즘
   
   }
        for (int i = 0; i < index.Length; i++)
   {
       max = index[i]; //MAx알고리즘
                mode = i;
           }

       ///////////////////////////////////////
       for문을 이용하여 출력
      ///////////////////////////////////////
        //for (int i = 0; i <= score.Length; i++)
        //{
        //    for (int j = 0; j < score.Length; j++)
        //    {
        //        if (score[i] == score[j])
        //        {
        //            count++;

        //            if (count > mode)
        //            {
        //                mode = score[j];
        //            }

        //        }

        //    }
       /////////////////////////////////////////// 
       foreach 문 이용하여 출력

       //////////////////////////////////////////    
            //foreach (int item in score)
            //{
            //    count = 0;

            //    foreach (int item1 in score)
            //    {
            //        if (item==item1)
            //        {
            //            count++;
            //        }
            //        if (count > mode)
            //        {
            //            mode = item;
            //        }
            //    }
 //}
////////////////////////////////////////////////
            //3.output
            Console.WriteLine("최빈값 :{0}", mode);
        }
} 
8. 순위

9. 정렬

10.병합

11.검색 Search

12.그룹 Grop
 

반응형

'.Net Project > .Net C#' 카테고리의 다른 글

15장 구조체(Struct), 열거형(Emumeration)  (0) 2009.08.06
14장 함수(메서드)  (0) 2009.08.05
12장 Consoal Array  (0) 2009.08.05
11장 컬렉션 반복  (0) 2009.08.05
10장 비트연산자  (0) 2009.08.04
posted by Magic_kit
2009. 8. 5. 10:01 .Net Project/.Net C#
반응형


using System;
public class ConsoleArray
{
    public static void Main()
    {
        1. 배열 선언
 
       int[] arr; //배열선언
        arr = new int[3]; //배열의 요소수 생성
               
        2.초기화 : 배열의 인덱스는 n-1규칙에 의해서 0부터
        arr[0] = 10;
        arr[1] = 20;
        arr[2] = 30;
      
        3.참조
        for문 사용하는 방법

        for (int i = 0; i < arr.Length; i++)
        {
            Console.WriteLine("{0}",arr[i]);
           
        }
       foreach 사용하는 방법
        foreach (var i in arr)
        {
            Console.WriteLine("{0}", i);
        }

    }
}

       - 배열 선언과 동시 참조 하며 요소수 생성
        int[] arr = new int[3];
        arr[0] = 10;
        arr[1] = 20;
        arr[2] = 30;

      - 배열 선언과 동시 참조하고, 요소수 생성
        int[] arr = new int[3] {10,20,30};
     
      - 배열 선언과 동시 참조하고, 요소수 생성 

        int[] arr = new int[] { 10, 20, 30 };

      - 최종적인 방식 사용
         int[] arr = { 10, 20, 30 };

      - 간단한 예제 연습
      - 선언과 동시에 참조하고 요소수 생성
         string[] 결제방식 = { "카드", "휴태폰", "통자입금" }; 
      - foreach문 사용하여 출력하고 할때
         foreach (var i in 결제방식)
           {
               Console.WriteLine("{0}", i);
           }

반응형

'.Net Project > .Net C#' 카테고리의 다른 글

14장 함수(메서드)  (0) 2009.08.05
13장 알고리즘(Algorithm)의 이해  (0) 2009.08.05
11장 컬렉션 반복  (0) 2009.08.05
10장 비트연산자  (0) 2009.08.04
09장 시프트연산자  (0) 2009.08.04
posted by Magic_kit
2009. 8. 5. 09:23 .Net Project/.Net C#
반응형


using System;
public class 컬렉션반복
{
    public static void Main(string[] args)
    {
        foreach문 : 배열 또는 컬렉션내에서 있는 만큼 반복
        string arr = "안녕하세요";
        
        arr 변수에 있는 값 중에서 문자 하나씩 뽑아서 출력
        for (int i = 0; i < arr.Length; i++)
        {
            Console.Write("{0}\t", arr[i]); //문자 하나씩 출력            
        }

        Console.WriteLine();

       arr에서 안녕하세요 에서 in이라는 인자를 참조하여 item에 넣어준다 
        foreach (char item in arr)
        {
            Console.Write("{0}\t", item); // \t 탭키, 문자 하나씩 출력
           
        }
    }
}


반응형

'.Net Project > .Net C#' 카테고리의 다른 글

13장 알고리즘(Algorithm)의 이해  (0) 2009.08.05
12장 Consoal Array  (0) 2009.08.05
10장 비트연산자  (0) 2009.08.04
09장 시프트연산자  (0) 2009.08.04
08장 산술연산자  (0) 2009.08.04
posted by Magic_kit
2009. 8. 4. 20:30 .Net Project/.Net C#
반응형

1. 비트 연산자
    & : AND : 논리곱 
    | : OR : 논리합
    ~  : NOT : 부정
    ^ : XOR : 베타적논리합

using System;
public class 비트연산자
{
    public static void Main()
    {
       2. 변수 선언 초기값
        int a = 3;
        int b = 2;
        int r = 0;

       3. 참조       
        r = a & b;
        Console.WriteLine(r); // 2

        r = a | b;
        Console.WriteLine(r); // 3

        r = ~a ;
        Console.WriteLine(r); 음수 이진법표현 -4 // 1:음수, 0양수

        r = a ^ b;
        Console.WriteLine(r); XOR(베타적논리합) 서로 다른때만(true)결과
    }
}

반응형

'.Net Project > .Net C#' 카테고리의 다른 글

12장 Consoal Array  (0) 2009.08.05
11장 컬렉션 반복  (0) 2009.08.05
09장 시프트연산자  (0) 2009.08.04
08장 산술연산자  (0) 2009.08.04
07장 상수  (0) 2009.08.04
posted by Magic_kit