pvjc25/du1/program.c

40 lines
947 B
C
Raw Normal View History

2025-02-25 13:40:34 +00:00
#include <stdio.h>
2025-02-25 13:53:52 +00:00
#include <string.h>
2025-02-25 13:40:34 +00:00
2025-02-25 13:53:52 +00:00
#define VELKOST_POLA 50
2025-02-25 13:40:34 +00:00
int main() {
2025-02-25 13:53:52 +00:00
int results[VELKOST_POLA];
memset(results, 0, sizeof(results));
2025-02-25 13:43:19 +00:00
int count = 0;
2025-02-25 13:53:52 +00:00
int value;
while (count < VELKOST_POLA) {
if (scanf("%d", &value) != 1) {
break;
}
if (value < 1) {
break;
2025-02-25 13:40:34 +00:00
}
2025-02-25 13:53:52 +00:00
results[count++] = value;
2025-02-25 13:43:19 +00:00
}
if (count == 0) {
printf("Chyba: Málo platných hodnôt.\n");
2025-02-25 13:53:52 +00:00
return 0;
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:53:52 +00:00
int max = results[0];
for (int i = 1; i < count; i++) {
if (results[i] > max) {
max = results[i];
2025-02-25 13:40:34 +00:00
}
}
for (int i = 0; i < count; i++) {
2025-02-25 13:53:52 +00:00
if (results[i] == max) {
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;
}