From d6265ab68e4bd7bc8ec9cc9ee1550276e52c4dc3 Mon Sep 17 00:00:00 2001 From: DevyatovaMY Date: Mon, 15 Apr 2024 14:52:54 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BC=D0=B8=D0=BD?= =?UTF-8?q?=D0=B8=D0=BC=D1=83=D0=BC=D0=B0/=D0=BC=D0=B0=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D0=BC=D1=83=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/main.cpp b/main.cpp index b237301..13d818d 100644 --- a/main.cpp +++ b/main.cpp @@ -24,25 +24,31 @@ input_data() { return in; } +void +find_minmax(const vector& numbers, double& min, double& max) { + min = numbers[0]; + max = numbers[0]; + for (double x : numbers) { + if (x > max ) + { + max = x; + } + if (x < min) + { + min = x; + } + } +} + int main() { const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; Input in = input_data(); vector bins(in.bin_count); - double min = in.numbers[0]; - double max = in.numbers[0]; - for (double x : in.numbers) - { - if (x < min) - { - min = x; - } - else if (x > max) - { - max = x; - } - } + double min = 0; + double max = 0; + find_minmax(in.numbers, min, max); auto bin_size = (max - min)/in.bin_count; for (double number : in.numbers) {