try3
This commit is contained in:
parent
06e1138f69
commit
bc79f9792c
@ -1,23 +1,21 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define VELKOST_POLA 50
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int results[VELKOST_POLA];
|
int results[50];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int max_value = 0;
|
int value;
|
||||||
|
|
||||||
while (count < VELKOST_POLA) {
|
printf("Zadajte výsledky súťaže (max 50 hodnôt, ukončite EOF alebo neplatným číslom):\n");
|
||||||
int temp;
|
|
||||||
if (scanf("%d", &temp) != 1 || temp < 1) {
|
while (scanf("%d", &value) == 1) {
|
||||||
|
if (value < 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
results[count] = temp;
|
results[count++] = value;
|
||||||
if (temp > max_value) {
|
if (count >= 50) {
|
||||||
max_value = temp;
|
break;
|
||||||
}
|
}
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
@ -29,9 +27,17 @@ int main() {
|
|||||||
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, results[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int max = results[0];
|
||||||
|
for (int i = 1; i < count; i++) {
|
||||||
|
if (results[i] > max) {
|
||||||
|
max = results[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Výherca je:\n");
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (results[i] == max_value) {
|
if (results[i] == max) {
|
||||||
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", i + 1, results[i]);
|
printf("Súťažiaci %d ktorý vypil %d pohárov.\n", i + 1, results[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user