pvjc24/cv3/program.c

123 lines
2.6 KiB
C
Raw Normal View History

2024-03-07 19:52:21 +00:00
#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;
}
2024-03-07 21:02:31 +00:00
//double vratenie2 (double x, double b, double v, double c,) {
2024-03-07 19:52:21 +00:00
//2x2+x+1
2024-03-07 21:02:31 +00:00
//double result = 0;
//result =
//return result;
//}
2024-03-07 19:52:21 +00:00
int main() {
2024-03-07 21:02:31 +00:00
double x = 0, b = 0, v = 0, c = 0 ;
2024-03-07 19:52:21 +00:00
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);
2024-03-07 21:02:31 +00:00
printf("prijate cislo:%.2f\n"x)
2024-03-07 19:52:21 +00:00
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);
2024-03-07 21:02:31 +00:00
printf("prijate cislo:%.2f\n"b)
2024-03-07 19:52:21 +00:00
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);
2024-03-07 21:02:31 +00:00
printf("prijate cislo:%.2f\n"v)
2024-03-07 19:52:21 +00:00
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);
2024-03-07 21:02:31 +00:00
printf("prijate cislo:%.2f\n"c)
2024-03-07 19:52:21 +00:00
memset(input, '\0', sizeoff(input));
}
if(x!= 0){
if(b!= 0){
if(v!=0){
if(c!=0){
result = vratenie (x, b, v, c);
}
else {
2024-03-07 19:55:39 +00:00
result= vratenie2 (x, b, v);
2024-03-07 19:52:21 +00:00
}
2024-03-07 19:57:53 +00:00
}
//else{
//result= vratenie3 (x, b);
2024-03-07 19:52:21 +00:00
}
}
2024-03-07 19:57:53 +00:00
//else{
//result= vratenie4 (x);
// }
2024-03-07 19:55:39 +00:00
2024-03-07 19:57:53 +00:00
//}
2024-03-07 19:52:21 +00:00
2024-03-07 21:02:31 +00:00
printf ("Vysledok je: %.2f\n", result );
2024-03-07 19:52:21 +00:00
//float coefficients[] = {57.0};
//int degree = 1;
/* double result = evaluate_polynomial(x, coefficients, degree - 1);
printf("Vysledok je: %.2f\n", result);*/
return 0;
}