pvjc24/cv2/program.c

50 lines
1.0 KiB
C
Raw Normal View History

2024-02-27 14:05:17 +00:00
#include <stdio.h>
int main() {
int cislo;
int pole[50];
int pocetCisel = 0;
while (pocetCisel < 50) {
if (scanf("%d", &cislo) == EOF) {
break;
}
if (cislo < 1) {
2024-02-27 16:16:11 +00:00
break;
2024-02-27 14:05:17 +00:00
}
pole[pocetCisel] = cislo;
pocetCisel++;
}
if (pocetCisel == 0) {
printf("Chyba: Málo platných hodnôt.\n");
return 1;
}
for (int i = 0; i < pocetCisel; i++) {
2024-02-27 14:10:02 +00:00
printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, pole[i]);
2024-02-27 14:05:17 +00:00
}
2024-02-27 15:26:04 +00:00
int maxPoharov = pole[0];
2024-02-27 16:06:40 +00:00
int pocetVyhercov = 1;
2024-02-27 14:05:17 +00:00
for (int i = 1; i < pocetCisel; i++) {
2024-02-27 15:26:04 +00:00
if (pole[i] > maxPoharov) {
maxPoharov = pole[i];
2024-02-27 16:06:40 +00:00
pocetVyhercov = 1;
2024-02-27 15:26:04 +00:00
} else if (pole[i] == maxPoharov) {
2024-02-27 16:06:40 +00:00
pocetVyhercov++;
2024-02-27 14:05:17 +00:00
}
}
2024-02-27 16:06:40 +00:00
for (int i = 0; i < pocetCisel; i++) {
if (pole[i] == maxPoharov) {
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", i + 1, pole[i]);
}
2024-02-27 15:26:04 +00:00
}
2024-02-27 14:05:17 +00:00
return 0;
}