(C#) 26. 배열 (array)
Data Structure
(C#) 26. 배열 (array)
(array) : Data Structure
- 최초 작성일: 2021년 3월 21일(월)
##
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
namespace array
{
class Program
{
static int GetHighestScore(int[] scores)
{
int max = 0;
foreach (int score in scores)
{
if (max < score) max = score;
}
return max;
}
static int GetAverageScore(int[] scores)
{
int sum = 0;
foreach(int score in scores)
{
sum += score;
}
return (int)sum / scores.Length;
}
static int GetIndexOf(int[] scores, int value)
{
for (int i = 0; i < scores.Length; i++)
{
if (value == scores[i]) return i;
}
return -1;
}
static void Sort(int[] scores)
{
}
static void Main(string[] args)
{
// 베열
//int[] scores = new int[5] { 10, 20, 30, 40, 50 } ;
//int[] scores = new int[] { 10, 20, 30, 40, 50 } ;
int[] scores = { 10, 30, 40, 20, 50 } ;
int maxValue = GetHighestScore(scores);
int avgValue = GetAverageScore(scores);
int index = GetIndexOf(scores, 30);
Console.WriteLine(maxValue);
Console.WriteLine(avgValue);
Console.WriteLine(index);
Sort(scores);
// 0 1 2 3 4
//scores[0] = 10;
//scores[1] = 20;
//scores[2] = 30;
//scores[3] = 40;
//scores[4] = 50;
//for (int i = 0; i < scores.Length; i++)
//{
// Console.WriteLine(scores[i]);
//}
//foreach(int score in scores)
//{
// Console.WriteLine(score);
//}
}
}
}
Result
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.
