From 23aa940839db09259cbde2eded1eebb463d9b18f Mon Sep 17 00:00:00 2001 From: Denys Sanchuk Date: Tue, 25 Feb 2025 13:53:52 +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.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du1/program.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/du1/program.c b/du1/program.c index 2ca44fd..11fa1d0 100644 --- a/du1/program.c +++ b/du1/program.c @@ -1,43 +1,39 @@ #include -#include -#include +#include -#define MAX_SIZE 50 +#define VELKOST_POLA 50 int main() { - int results[MAX_SIZE]; + int results[VELKOST_POLA]; + memset(results, 0, sizeof(results)); 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; + int value; + while (count < VELKOST_POLA) { + if (scanf("%d", &value) != 1) { + break; } - results[count++] = num; + if (value < 1) { + break; + } + results[count++] = value; } - if (count == 0) { printf("Chyba: Málo platných hodnôt.\n"); - return 1; + return 0; } - for (int i = 0; i < count; i++) { printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, results[i]); } - - int max_val = INT_MIN; - for (int i = 0; i < count; i++) { - if (results[i] > max_val) { - max_val = results[i]; + int max = results[0]; + for (int i = 1; i < count; i++) { + if (results[i] > max) { + max = results[i]; } } - for (int i = 0; i < count; i++) { - if (results[i] == max_val) { + if (results[i] == max) { printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", i + 1, results[i]); } } - return 0; }