pvjc25/du1/program.c

44 lines
964 B
C
Raw Normal View History

2025-02-25 13:40:34 +00:00
#include <stdio.h>
#include <stdlib.h>
2025-02-25 13:43:19 +00:00
#include <limits.h>
2025-02-25 13:40:34 +00:00
2025-02-25 13:43:19 +00:00
#define MAX_SIZE 50
2025-02-25 13:40:34 +00:00
int main() {
2025-02-25 13:43:19 +00:00
int results[MAX_SIZE];
int count = 0;
int num;
while (count < MAX_SIZE && scanf("%d", &num) == 1) {
if (num < 1) {
2025-02-25 13:40:34 +00:00
printf("Chyba: Málo platných hodnôt.\n");
return 1;
}
2025-02-25 13:43:19 +00:00
results[count++] = num;
}
if (count == 0) {
printf("Chyba: Málo platných hodnôt.\n");
return 1;
2025-02-25 13:40:34 +00:00
}
for (int i = 0; i < count; i++) {
printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, results[i]);
}
2025-02-25 13:43:19 +00:00
int max_val = INT_MIN;
for (int i = 0; i < count; i++) {
if (results[i] > max_val) {
max_val = results[i];
2025-02-25 13:40:34 +00:00
}
}
for (int i = 0; i < count; i++) {
2025-02-25 13:43:19 +00:00
if (results[i] == max_val) {
2025-02-25 13:40:34 +00:00
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", i + 1, results[i]);
}
}
return 0;
}