This commit is contained in:
Michal Utľák 2024-02-27 15:05:17 +01:00
parent 291e3d923e
commit bb7c38f6a0

View File

@ -0,0 +1,44 @@
#include <stdio.h>
int main() {
int cislo;
int pole[50];
int pocetCisel = 0;
printf("Zadajte maximalne 50 cisel:\n");
while (pocetCisel < 50) {
if (scanf("%d", &cislo) == EOF) {
break;
}
if (cislo < 1) {
printf("Neplatne cislo zadane. Koniec nacitania.\n");
return 1;
}
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++) {
printf("Sutaziaci %d vypil %d pohárov.\n", i + 1, pole[i]);
}
int vyhercaIndex = 0;
for (int i = 1; i < pocetCisel; i++) {
if (pole[i] > pole[vyhercaIndex]) {
vyhercaIndex = i;
}
}
printf("Výherca je sútaziaci %d, ktory vypil %d poharov.\n", vyhercaIndex + 1, pole[vyhercaIndex]);
return 0;
}