diff --git a/cv2/program.c b/cv2/program.c new file mode 100644 index 0000000..ce0c681 --- /dev/null +++ b/cv2/program.c @@ -0,0 +1,56 @@ +#include +#include + +#define MAX_CONTESTANTS 50 + +int main() { + int results[MAX_CONTESTANTS]; + int num_results = 0; + int max_cups = 0; + + // Read and process input + while (1) { + int value; + if (scanf("%d", &value) != 1) { + printf("Chyba: Nesprávny vstup.\n"); + return 1; + } + if (value < 1) { + printf("Chyba: Nesprávna hodnota.\n"); + return 1; + } + if (num_results >= MAX_CONTESTANTS) { + printf("Chyba: Príliš veľa hodnôt.\n"); + return 1; + } + results[num_results++] = value; + + char next_char = getchar(); + if (next_char == '\n' || next_char == EOF) { + break; + } + ungetc(next_char, stdin); + } + + if (num_results == 0) { + printf("Chyba: Málo platných hodnôt.\n"); + return 1; + } + + // Find the maximum number of cups drunk + for (int i = 0; i < num_results; i++) { + if (results[i] > max_cups) { + max_cups = results[i]; + } + } + + // Print results and winners + for (int i = 0; i < num_results; i++) { + printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, results[i]); + if (results[i] == max_cups) { + printf("Výherca je súťažiaci č. %d ktorý vypil %d pohárov.\n", i + 1, results[i]); + } + } + + return 0; +} diff --git a/cv3/program.c b/cv3/program.c new file mode 100644 index 0000000..b210dc9 --- /dev/null +++ b/cv3/program.c @@ -0,0 +1,50 @@ +#include +#include + +#define MAX_COEFFICIENTS 100 + +double evaluate_polynomial(double x, double coefficients[], int degree) { + double result = 0; + for (int i = degree; i >= 0; i--) { + result = result * x + coefficients[i]; + } + return result; +} + +int main() { + double x; + double coefficients[MAX_COEFFICIENTS]; + int degree; + + // Read the value of x + if (scanf("%lf", &x) != 1) { + printf("Error: Failed to read the value of x.\n"); + return 1; + } + + // Read the coefficients of the polynomial + int coefficient_number = 1; + while (scanf("%lf", &coefficients[coefficient_number - 1]) == 1) { + coefficient_number++; + if (coefficient_number > MAX_COEFFICIENTS) { + printf("Error: Too many coefficients.\n"); + return 1; + } + } + + degree = coefficient_number - 2; // degree of polynomial = number of coefficients - 1 + + // Check if at least one coefficient is loaded + if (degree < 0) { + printf("Error: No coefficients loaded.\n"); + return 1; + } + + // Evaluate the polynomial + double result = evaluate_polynomial(x, coefficients, degree); + + // Print the result rounded to two decimal places + printf("The output is: %.2lf\n", result); + + return 0; +}