skuska
This commit is contained in:
parent
b57883da10
commit
4c354b4b39
49
du2/program.c
Normal file
49
du2/program.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define LINE_SIZE 100
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
char line[LINE_SIZE];
|
||||||
|
double x, result;
|
||||||
|
double coefficient;
|
||||||
|
int first = 1;
|
||||||
|
|
||||||
|
// Read the evaluation point
|
||||||
|
if (fgets(line, LINE_SIZE, stdin) == NULL || sscanf(line, "%lf", &x) != 1) {
|
||||||
|
printf("Chyba: Neplatná hodnota pre x.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = 0;
|
||||||
|
|
||||||
|
// Read coefficients until EOF or an empty line
|
||||||
|
while (fgets(line, LINE_SIZE, stdin) != NULL) {
|
||||||
|
if (strlen(line) <= 1) break; // Empty line check
|
||||||
|
|
||||||
|
if (sscanf(line, "%lf", &coefficient) != 1) {
|
||||||
|
printf("Chyba: Neplatný koeficient.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (first) {
|
||||||
|
result = coefficient;
|
||||||
|
first = 0;
|
||||||
|
} else {
|
||||||
|
result = result * x + coefficient;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (first) {
|
||||||
|
printf("Chyba: Neboli zadané žiadne koeficienty.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print result rounded to two decimal places
|
||||||
|
printf("Vysledok je: %.2f\n", result);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user