최소, 최대
2023. 1. 28. 22:14ㆍ개인공부/코딩테스트
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
|
#include <iostream>
using namespace std;
int main()
{
int MaxNum = 0, MinimumNum = 0, NumOfNum = 0;
cin >> NumOfNum;
int* pNum = new int[NumOfNum];
for (int i = 0; i < NumOfNum; ++i)
{
int a = 0;
cin >> a;
pNum[i] = a;
}
MaxNum = pNum[0];
MinimumNum = pNum[0];
for (int i = 1; i < NumOfNum; ++i)
{
if (MaxNum < pNum[i])
MaxNum = pNum[i];
else if (MinimumNum > pNum[i])
MinimumNum = pNum[i];
}
cout << MinimumNum << " " << MaxNum;
return 0;
}
|
cs |