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

82 lines
1.9 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;
}
// 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 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));
}
// 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);
}
*/
result = vratenie(x, b, v, c);
printf("Vysledok je: %.2f\n", result);
return 0;
}