반응형
Untitled Document.md

뇌를 자극하는 C# 5.0 프로그래밍 Chapter10 연습문제


1. 다음 배열 선언 문장 중 올바르지 않은 것을 고르세요.

  1. int[] array = new string[3]{“안녕”, “Hello”, “Halo”};
  2. int[] array = new int[3]{1, 2, 3};
  3. int[] array = new int[]{1, 2, 3};
  4. int[] array = {1, 2, 3};

1번이 올바르지 않다. int형 배열 array를 만들겠다고, 알려줬는데 실제 객체를 만들 때는 string형으로 생성하기 때문에 올바르지 않다. 즉, 만들겠다고 선언한 형과 실제 생성하는 객체 형이 달라서 안된다.



2. 두 행렬의 곱은 다음과 같이 계산합니다. 다음 두 행렬 A와 B의 곱을 2차원 배열을 이용하는 계산하는 프로그램을 작성하세요.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
 
namespace Ex10_2
{
    class MainApp
    {
        static void Main(string[] args)
        {
            int[,] A = new int[22]{{32},{14}};
            int[,] B = new int[22]{{92},{17}};
            int[,] result = new int[22];
 
            result[00= A[00* B[00+ A[01* B[10];
            result[01= A[00* B[01+ A[01* B[11];
            result[10= A[10* B[00+ A[11* B[10];
            result[11= A[10* B[01+ A[11* B[11];
 
            Console.WriteLine("{0}, {1}", result[00], result[01]);
            Console.WriteLine("{0}, {1}", result[10], result[11]);
        }
    }
}
cs

출력결과




3. 다음 코드의 출력 결과는 무엇일까요?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Collections;
 
namespace Ex10_3
{
    class MainApp
    {
        static void Main(string[] args)
        {
            Stack stack = new Stack();
            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            stack.Push(4);
            stack.Push(5);
 
            while (stack.Count > 0)
                Console.WriteLine(stack.Pop());
        }
    }
}
cs

출력결과



4. 다음 코드의 출력 결과는 무엇일까요?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Collections;
 
namespace Ex10_4
{
    class MainApp
    {
        static void Main(string[] args)
        {
            Queue que = new Queue();
            que.Enqueue(1);
            que.Enqueue(2);
            que.Enqueue(3);
            que.Enqueue(4);
            que.Enqueue(5);
 
            while (que.Count > 0)
                Console.WriteLine(que.Dequeue());
        }
    }
}
cs

출력결과



5. 다음과 같은 결과를 출력하도록 아래의 코드를 완성하세요.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using System.Collections;
 
namespace Ex10_5
{
    class MainApp
    {
        static void Main(string[] args)
        {
            Hashtable ht = new Hashtable();
 
            ht["회사"= "Microsoft";
            ht["URL"= "www.microsoft.com";
 
            Console.WriteLine("회사 : {0}", ht["회사"]);
            Console.WriteLine("URL : {0}", ht["URL"]);
        }
    }
}
cs

출력결과




반응형

+ Recent posts