From a9eb7f112e7127030b2d387227fb6be4d2231fad Mon Sep 17 00:00:00 2001 From: ak643du Date: Wed, 28 Feb 2024 13:49:54 +0100 Subject: [PATCH] G --- cv2/program.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/cv2/program.c b/cv2/program.c index 38b76d2..b954bc4 100644 --- a/cv2/program.c +++ b/cv2/program.c @@ -22,7 +22,37 @@ int main(){ for (int i = 0; i < count; i++) { printf("Sutaziaci č. %d vypil %d pohárov.\n", i + 1, field[i]); } - printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n",i+1,field[i]); + printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n",i+1,field[i]);#include + +#define FIELD_SIZE 52 + +int main(){ + int field[FIELD_SIZE] = {0}; + int count = 0; + int max_num = 0; + int input; + int winner_index = 0; + + while (count < FIELD_SIZE) { + if (scanf("%d", &input) != 1) { + break; + } + if (input < 0) { + break; + } + field[count] = input; + count++; + } + + for (int i = 0; i < count; i++) { + printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, field[i]); + if (field[i] > max_num) { + max_num = field[i]; + winner_index = i; + } + } + + printf("Výherca je súťažiaci %d, ktorý vypil %d pohárov.\n", winner_index + 1, max_num); return 0; }