pvjc24/cv3/program.c

67 lines
1.6 KiB
C
Raw Normal View History

2024-03-07 19:52:21 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
2024-03-07 21:05:01 +00:00
double vratenie(double x, double b, double v, double c) {
2024-03-07 21:11:05 +00:00
double result = 0;
2024-03-07 21:07:51 +00:00
result = (b * (x * x)) + (v * x) + c;
2024-03-07 19:52:21 +00:00
return result;
}
int main() {
2024-03-07 21:05:01 +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];
2024-03-07 21:05:01 +00:00
// 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));
2024-03-07 19:52:21 +00:00
}
2024-03-07 21:05:01 +00:00
// 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));
2024-03-07 19:52:21 +00:00
}
2024-03-07 21:05:01 +00:00
// 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));
2024-03-07 19:52:21 +00:00
}
2024-03-07 21:05:01 +00:00
// 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));
2024-03-07 19:52:21 +00:00
}
2024-03-07 21:17:10 +00:00
// Calculate the result
2024-03-07 21:05:01 +00:00
result = vratenie(x, b, v, c);
2024-03-07 21:17:10 +00:00
// Print the result
2024-03-07 21:05:01 +00:00
printf("Vysledok je: %.2f\n", result);
2024-03-07 19:52:21 +00:00
return 0;
2024-03-07 21:17:10 +00:00
}