Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cassert>
- #include <iostream>
- void find_min_and_max(int* v, int n, int& min, int& max) {
- assert(n > 0);
- max = min = v[0];
- for (int i = 1; i < n; ++i) {
- if (v[i] > max) {
- max = v[i];
- }
- if (v[i] < min) {
- min = v[i];
- }
- }
- }
- int main() {
- int n = 0;
- std::cin >> n;
- int* p = new int[n];
- for (int i = 0; i < n; ++i) {
- std::cin >> p[i];
- }
- int min = 0, max = 0;
- find_min_and_max(p, n, min, max);
- std::cout << min << " " << max << std::endl;
- delete[] p;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement