This commit is contained in:
Macko 2024-03-07 22:05:01 +01:00
parent b524557c3e
commit 9aba7daa57

View File

@ -2,122 +2,79 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define MAX_COEFFICIENTS 100 double vratenie(double x, double b, double v, double c) {
double result = (b * (x * x)) + (v * x) + c;
/*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];
}
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; return result;
} }
//double vratenie2 (double x, double b, double v, double c,) { // Uncomment if you intend to use this function
//2x2+x+1 /*
//double result = 0; double vratenie2(double x, double b, double v, double c) {
//result = double result = (b * (x * x)) + (v * x) + c;
//return result; return result;
//} }
*/
int main() { int main() {
double x = 0, b = 0, v = 0, c = 0; double x = 0, b = 0, v = 0, c = 0;
double result = 0; double result = 0;
char input[5]; char input[5];
//tu spracovavam x // Input for x
fgets(input, sizeoff(input), stdin); fgets(input, sizeof(input), stdin);
if (input[0] == '\0') {
if (\input[0] == '\0' ){printf("Chyba: Neplatná hodnota x.\n"); printf("Chyba: Neplatná hodnota x.\n");
return 1; return 1;
} else { } else {
x = atof(input); x = atof(input);
printf("prijate cislo:%.2f\n"x) printf("Prijate cislo: %.2f\n", x);
memset(input, '\0', sizeoff(input)); memset(input, '\0', sizeof(input));
} }
//tu spracovavam b // Input for b
fgets(input, sizeoff(input), stdin); fgets(input, sizeof(input), stdin);
if (input[0] == '\0') {
if (\input[0] == '\0' ){printf("Chyba: Neplatná hodnota x.\n"); printf("Chyba: Neplatná hodnota b.\n");
return 1; return 1;
} else { } else {
b = atof(input); b = atof(input);
printf("prijate cislo:%.2f\n"b) printf("Prijate cislo: %.2f\n", b);
memset(input, '\0', sizeoff(input)); memset(input, '\0', sizeof(input));
} }
//tu spracovavam v // Input for v
fgets(input, sizeoff(input), stdin); fgets(input, sizeof(input), stdin);
if (input[0] == '\0') {
if (\input[0] == '\0' ){printf("Chyba: Neplatná hodnota x.\n"); printf("Chyba: Neplatná hodnota v.\n");
return 1; return 1;
} else { } else {
v = atof(input); v = atof(input);
printf("prijate cislo:%.2f\n"v) printf("Prijate cislo: %.2f\n", v);
memset(input, '\0', sizeoff(input)); memset(input, '\0', sizeof(input));
} }
//tu spracuvavam c // Input for c
fgets(input, sizeoff(input), stdin); fgets(input, sizeof(input), stdin);
if (input[0] == '\0') {
if (\input[0] == '\0' ){printf("Chyba: Neplatná hodnota x.\n"); printf("Chyba: Neplatná hodnota c.\n");
return 1; return 1;
} else { } else {
c = atof(input); c = atof(input);
printf("prijate cislo:%.2f\n"c) printf("Prijate cislo: %.2f\n", c);
memset(input, '\0', sizeoff(input)); memset(input, '\0', sizeof(input));
} }
if(x!= 0){
if(b!= 0){ // Uncomment to use vratenie2 function
if(v!=0){ /*
if(c!=0){ if (x != 0 && b != 0 && v != 0 && c != 0) {
result = vratenie2(x, b, v, c);
} else {
result = vratenie(x, b, v, c); result = vratenie(x, b, v, c);
} }
else { */
result= vratenie2 (x, b, v);
}
}
//else{
//result= vratenie3 (x, b);
}
}
//else{
//result= vratenie4 (x);
// }
//}
result = vratenie(x, b, v, c);
printf("Vysledok je: %.2f\n", result); 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);*/
return 0; return 0;
} }