-
Notifications
You must be signed in to change notification settings - Fork 0
/
mid_p3.c
74 lines (56 loc) · 1.14 KB
/
mid_p3.c
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
#include <stdio.h>
#pragma warning(disable:4996)
int* MAX(int* pArr, int num);
int* MIN(int* pArr, int num);
int main(void) {
int Arr[10];
int* pArr = Arr;
int num = 10;
printf("배열 원소 10개를 입력하시오...\n");
for (int i = 0; i < 10; i++) {
printf("arr[%d] : ", i);
scanf("%d", &Arr[i]);
}
printf("입력 데이터 : ");
for (int i = 0; i < 10; i++) {
printf("%d ", Arr[i]);
}
int maximum;
int* pmaximum = MAX(pArr, num);
printf("\n최대값 : %d, 위치(첨자) : %d\n", *pmaximum, *pmaximum - 1);
int minimum;
int* pminimum = MIN(pArr, num);
printf("최소값 : %d, 위치(첨자) : %d", *pminimum, *pminimum - 1);
}
int* MAX(int* pArr, int num) {
int max1 = *pArr;
int res;
int* pres = &res;
int flag = *pArr;
for (int i = 0; i < num; i++) {
if (flag > pArr[i]) {
res = flag;
}
else if (flag < pArr[i]) {
res = pArr[i];
flag = res;
}
}
return &res;
}
int* MIN(int* pArr, int num) {
int min1 = *pArr;
int res;
int* pres = &res;
int flag = *pArr;
for (int i = 0; i < num; i++) {
if (flag < pArr[i]) {
res = flag;
}
else if (flag > pArr[i]) {
res = pArr[i];
flag = res;
}
}
return &res;
}