Обновить du1/program.c

This commit is contained in:
Bohdana Marchenko 2025-02-27 11:08:55 +00:00
parent 4777e86b00
commit e920349d4c

View File

@ -1,14 +1,17 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define VELKOST_POLA 52
int main() { int main() {
int results[50]; int vysledky[VELKOST_POLA];
int count = 0; int count = 0;
int max_hodnota = 0;
int number; int number;
while (count < 50 && scanf("%d", &number) == 1) { while (count < VELKOST_POLA && scanf("%d", &number) == 1) {
if (number >= 1) { if (number >= 1) {
results[count] = number; vysledky[count] = number;
count++; count++;
} }
} }
@ -18,22 +21,29 @@ int main() {
return 1; return 1;
} }
int max_value = results[0]; max_hodnota = vysledky[0];
for (int i = 1; i < count; i++) { for (int i = 1; i < count; i++) {
if (results[i] > max_value) { if (vysledky[i] > max_hodnota) {
max_value = results[i]; max_hodnota = vysledky[i];
} }
} }
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, results[i]); printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, vysledky[i]);
} }
printf("Výherca je súťažiaci/í ");
int isFirst = 1;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
if (results[i] == max_value) { if (vysledky[i] == max_hodnota) {
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", i + 1, results[i]); if (!isFirst) {
printf(" a ");
}
printf("súťažiaci %d", i + 1);
isFirst = 0;
} }
} }
printf(" ktorý vypil %d pohárov.\n", max_hodnota);
return 0; return 0;
} }