From e8c1836d526fc293d0b73624c3469c21f14483c5 Mon Sep 17 00:00:00 2001 From: Denys Sanchuk Date: Tue, 25 Feb 2025 13:43:19 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20du1/program.cv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du1/program.cv | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/du1/program.cv b/du1/program.cv index b83e978..2ca44fd 100644 --- a/du1/program.cv +++ b/du1/program.cv @@ -1,34 +1,40 @@ #include #include -#include +#include -#define MAX_CONTESTANTS 50 +#define MAX_SIZE 50 int main() { - int results[MAX_CONTESTANTS]; - int count = 0, value; - - while (count < MAX_CONTESTANTS) { - if (scanf("%d", &value) != 1 || value < 1) { + int results[MAX_SIZE]; + int count = 0; + int num; + + while (count < MAX_SIZE && scanf("%d", &num) == 1) { + if (num < 1) { printf("Chyba: Málo platných hodnôt.\n"); return 1; } - results[count++] = value; + results[count++] = num; + } + + if (count == 0) { + printf("Chyba: Málo platných hodnôt.\n"); + return 1; } for (int i = 0; i < count; i++) { printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, results[i]); } - int max_value = results[0]; - for (int i = 1; i < count; i++) { - if (results[i] > max_value) { - max_value = results[i]; + int max_val = INT_MIN; + for (int i = 0; i < count; i++) { + if (results[i] > max_val) { + max_val = results[i]; } } for (int i = 0; i < count; i++) { - if (results[i] == max_value) { + if (results[i] == max_val) { printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", i + 1, results[i]); } }