-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmax_min.cpp
46 lines (42 loc) · 871 Bytes
/
max_min.cpp
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
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n = 8;
int arr[n] = {1, 3, 2, 5, 6, 8, 2, 8};
int sum = 0;
for (int i = 0; i < 8; i++)
{
sum += arr[i];
}
int mid = sum / n;
int min = -1;
int max = -1;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (mid > arr[j])
min = arr[j];
if (mid < arr[j])
max = arr[j];
}
}
int ans = 0;
for (int i = 0; i < n; i++)
{
if (arr[i] <= mid && arr[i] > min)
{
ans = arr[i];
}
else if (arr[i] >= mid && arr[i] <max)
{
ans = arr[i];
}
}
cout << ans << endl;
cout<<mid<<" "<<" sum "<<sum<<endl;
cout<<" max "<<max<<" min"<<min<<endl;
return 0;
}