반응형
뇌를 자극하는 C# 5.0 프로그래밍 Chapter10 연습문제
1. 다음 배열 선언 문장 중 올바르지 않은 것을 고르세요.
- int[] array = new string[3]{“안녕”, “Hello”, “Halo”};
- int[] array = new int[3]{1, 2, 3};
- int[] array = new int[]{1, 2, 3};
- 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[2, 2]{{3, 2},{1, 4}}; int[,] B = new int[2, 2]{{9, 2},{1, 7}}; int[,] result = new int[2, 2]; result[0, 0] = A[0, 0] * B[0, 0] + A[0, 1] * B[1, 0]; result[0, 1] = A[0, 0] * B[0, 1] + A[0, 1] * B[1, 1]; result[1, 0] = A[1, 0] * B[0, 0] + A[1, 1] * B[1, 0]; result[1, 1] = A[1, 0] * B[0, 1] + A[1, 1] * B[1, 1]; Console.WriteLine("{0}, {1}", result[0, 0], result[0, 1]); Console.WriteLine("{0}, {1}", result[1, 0], result[1, 1]); } } } | 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 |
출력결과
반응형
'programming' 카테고리의 다른 글
뇌를 자극하는 C# 5.0 프로그래밍 Chapter12 연습문제 풀이 (0) | 2016.03.31 |
---|---|
뇌를 자극하는 C# 5.0 프로그래밍 Chapter11 연습문제 풀이 (0) | 2016.03.30 |
뇌를 자극하는 C# 5.0 프로그래밍 Chapter9 연습문제 풀이 (0) | 2016.01.08 |
뇌를 자극하는 C# 5.0 프로그래밍 Chapter8 연습문제 풀이 (0) | 2016.01.08 |
뇌를 자극하는 C# 5.0 프로그래밍 Chapter7 연습문제 풀이 (0) | 2016.01.07 |