121 lines
2.5 KiB
C
121 lines
2.5 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#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];
|
|
}
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
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:%.2lf\n"x)
|
|
memset(input, '\0', sizeoff(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:%.2lf\n"b)
|
|
memset(input, '\0', sizeoff(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:%.2lf\n"v)
|
|
memset(input, '\0', sizeoff(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:%.2lf\n"c)
|
|
memset(input, '\0', sizeoff(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);
|
|
}
|
|
|
|
|
|
|
|
|
|
printf ("Vysledok je: %.2lf\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;
|
|
} |