pvjc25/du1/program.c

45 lines
1.0 KiB
C
Raw Normal View History

2025-02-27 17:19:02 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define VELKOST_POLA 50
int main() {
int results[VELKOST_POLA];
memset(results, 0, VELKOST_POLA * sizeof(int));
int max_value = 0;
int count = 0;
printf("Zadajte výsledky súťažiacich (max %d, ukončite nečíselným vstupom alebo EOF):\n", VELKOST_POLA);
for (int i = 0; i < VELKOST_POLA; i++) {
int temp;
if (scanf("%d", &temp) != 1 || temp < 1) {
break;
}
results[i] = temp;
if (temp > max_value) {
max_value = temp;
}
count++;
}
if (count == 0) {
printf("Chyba: Málo platných hodnôt.\n");
return 1;
}
for (int i = 0; i < count; i++) {
printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, results[i]);
}
for (int i = 0; i < count; i++) {
if (results[i] == max_value) {
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", i + 1, results[i]);
}
}
return 0;
}