-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmini_max_sum.cpp
More file actions
46 lines (35 loc) · 943 Bytes
/
mini_max_sum.cpp
File metadata and controls
46 lines (35 loc) · 943 Bytes
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
/*
given an array of n, find the largest int and smallest int and add them
void mini_max_sum(std::vector<int> arr)
{
int max{ arr.at(0) }, min{ arr.at(0) }, sum{ 0 };
for (int it : arr)
{
if (it > max) max = it;
if (it < min) min = it;
sum += it;
}
std::cout << (sum - max) << ' ';
std::cout << (sum - min) << std::endl;
}
*/
#include <bits/stdc++.h>
void mini_max_sum(std::vector<int> arr)
{
int max{ arr.at(0) }, min{ arr.at(0) };
long sum{ 0 };
for (int it : arr)
{
if (it > max) max = it;
if (it < min) min = it;
sum += it;
}
std::cout << (sum - max) << ' ';
std::cout << (sum - min) << std::endl;
}
int main(int argc, char const *argv[])
{
std::vector<int> arr{ 256741038, 623958417, 467905213, 714532089, 938071625 };
mini_max_sum(arr);
return 0;
}