pvjc24/cv3/program.c
2024-03-07 22:19:54 +01:00

67 lines
1.6 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
double vratenie(double x, double b, double v, double c) {
double result = 0;
result = (b * (x * x)) + (v * x) + c;
return result;
}
int main() {
double x = 0, b = 0, v = 0, c = 0;
double result = 0;
char input[5];
// 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));
}
// 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));
}
// 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));
}
// 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));
}
// Calculate the result
result = vratenie(x, b, v, c);
// Print the result
printf("Vysledok je: %.2lf\n", result);
return 0;
}