Обновить du1/program.c
This commit is contained in:
parent
5adbc45d85
commit
d6dae4e82d
@ -1,23 +1,26 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int results[50];
|
int results[50];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int number;
|
int number;
|
||||||
|
|
||||||
while (scanf("%d", &number) == 1) {
|
while (count < 50 && scanf("%d", &number) == 1) {
|
||||||
if (number > 0) {
|
if (number >= 1) {
|
||||||
results[count] = number;
|
results[count] = number;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
if (count == 0) {
|
||||||
printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, results[i]);
|
printf("Chyba: Málo platných hodnôt.\n");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int max_value = results[0];
|
int max_value = results[0];
|
||||||
int winner_index = 0;
|
int winner_index = 0;
|
||||||
|
|
||||||
for (int i = 1; i < count; i++) {
|
for (int i = 1; i < count; i++) {
|
||||||
if (results[i] > max_value) {
|
if (results[i] > max_value) {
|
||||||
max_value = results[i];
|
max_value = results[i];
|
||||||
@ -25,6 +28,11 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", winner_index + 1, max_value);
|
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", winner_index + 1, max_value);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user