pvjc25/du1/program.c

40 lines
854 B
C
Raw Normal View History

2025-02-27 10:45:09 +00:00
#include <stdio.h>
2025-02-27 10:58:17 +00:00
#include <stdlib.h>
2025-02-27 10:45:09 +00:00
int main() {
int results[50];
int count = 0;
int number;
2025-02-27 10:58:17 +00:00
while (count < 50 && scanf("%d", &number) == 1) {
if (number >= 1) {
2025-02-27 10:45:09 +00:00
results[count] = number;
count++;
}
}
2025-02-27 10:58:17 +00:00
if (count == 0) {
printf("Chyba: Málo platných hodnôt.\n");
return 1;
2025-02-27 10:45:09 +00:00
}
int max_value = results[0];
2025-02-27 10:55:57 +00:00
int winner_index = 0;
2025-02-27 10:58:17 +00:00
2025-02-27 10:45:09 +00:00
for (int i = 1; i < count; i++) {
if (results[i] > max_value) {
max_value = results[i];
2025-02-27 10:55:57 +00:00
winner_index = i;
2025-02-27 10:45:09 +00:00
}
}
2025-02-27 10:58:17 +00:00
for (int i = 0; i < count; i++) {
printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, results[i]);
}
// Vypíše víťaza
2025-02-27 10:55:57 +00:00
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", winner_index + 1, max_value);
2025-02-27 10:45:09 +00:00
return 0;
2025-02-27 10:55:57 +00:00
}