diff --git a/cv3/program.c b/cv3/program.c index bee842b..3abca3b 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -2,122 +2,79 @@ #include #include -#define MAX_COEFFICIENTS 100 - -/*double evaluate_polynomial(double x, double coefficients[], int degree) { - double result = coefficients[degree]; - for (int i = degree - 1; i >= 0; i--) { - result = result * x + coefficients[i]; - } +double vratenie(double x, double b, double v, double c) { + double result = (b * (x * x)) + (v * x) + c; return result; -}*/ - -double vratenie (double x, double b, double v, double c,) { -//3x2+2x+1 -//(m*(x*x)) + (n*x) + o -double result = 0; -result = (b*(x*x)) + (v*x) + c; -return result; } -//double vratenie2 (double x, double b, double v, double c,) { -//2x2+x+1 -//double result = 0; -//result = -//return result; -//} - - +// Uncomment if you intend to use this function +/* +double vratenie2(double x, double b, double v, double c) { + double result = (b * (x * x)) + (v * x) + c; + return result; +} +*/ int main() { - - double x = 0, b = 0, v = 0, c = 0 ; - + double x = 0, b = 0, v = 0, c = 0; double result = 0; char input[5]; - //tu spracovavam x - fgets(input, sizeoff(input), stdin); - - if (\input[0] == '\0' ){printf("Chyba: Neplatná hodnota x.\n"); - return 1; - - } else{ - x= atof(input); - printf("prijate cislo:%.2f\n"x) - memset(input, '\0', sizeoff(input)); + // Input for x + fgets(input, sizeof(input), stdin); + if (input[0] == '\0') { + printf("Chyba: Neplatná hodnota x.\n"); + return 1; + } else { + x = atof(input); + printf("Prijate cislo: %.2f\n", x); + memset(input, '\0', sizeof(input)); } - //tu spracovavam b - fgets(input, sizeoff(input), stdin); - - if (\input[0] == '\0' ){printf("Chyba: Neplatná hodnota x.\n"); - return 1; - - } else{ - b= atof(input); - printf("prijate cislo:%.2f\n"b) - memset(input, '\0', sizeoff(input)); + // Input for b + fgets(input, sizeof(input), stdin); + if (input[0] == '\0') { + printf("Chyba: Neplatná hodnota b.\n"); + return 1; + } else { + b = atof(input); + printf("Prijate cislo: %.2f\n", b); + memset(input, '\0', sizeof(input)); } - //tu spracovavam v - fgets(input, sizeoff(input), stdin); - - if (\input[0] == '\0' ){printf("Chyba: Neplatná hodnota x.\n"); - return 1; - - } else{ - v= atof(input); - printf("prijate cislo:%.2f\n"v) - memset(input, '\0', sizeoff(input)); + // Input for v + fgets(input, sizeof(input), stdin); + if (input[0] == '\0') { + printf("Chyba: Neplatná hodnota v.\n"); + return 1; + } else { + v = atof(input); + printf("Prijate cislo: %.2f\n", v); + memset(input, '\0', sizeof(input)); } - //tu spracuvavam c - fgets(input, sizeoff(input), stdin); - - if (\input[0] == '\0' ){printf("Chyba: Neplatná hodnota x.\n"); - return 1; - - } else{ - c= atof(input); - printf("prijate cislo:%.2f\n"c) - memset(input, '\0', sizeoff(input)); + // Input for c + fgets(input, sizeof(input), stdin); + if (input[0] == '\0') { + printf("Chyba: Neplatná hodnota c.\n"); + return 1; + } else { + c = atof(input); + printf("Prijate cislo: %.2f\n", c); + memset(input, '\0', sizeof(input)); } - if(x!= 0){ - if(b!= 0){ - if(v!=0){ - if(c!=0){ - result = vratenie (x, b, v, c); - } - else { - result= vratenie2 (x, b, v); - } - } - //else{ - //result= vratenie3 (x, b); - } - } - //else{ - //result= vratenie4 (x); - // } + // Uncomment to use vratenie2 function + /* + if (x != 0 && b != 0 && v != 0 && c != 0) { + result = vratenie2(x, b, v, c); + } else { + result = vratenie(x, b, v, c); + } + */ - //} - - - - - - printf ("Vysledok je: %.2f\n", result ); - - - - - //float coefficients[] = {57.0}; - //int degree = 1; - - /* double result = evaluate_polynomial(x, coefficients, degree - 1); - printf("Vysledok je: %.2f\n", result);*/ + result = vratenie(x, b, v, c); + printf("Vysledok je: %.2f\n", result); return 0; -} \ No newline at end of file +}