This commit is contained in:
Denis Landa 2025-03-07 00:16:39 +01:00
parent 80403c694a
commit e24c13ad36

40
du2/program.c Normal file
View File

@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define LINE_SIZE 100
int main(){
char line[LINE_SIZE];
float x;
float coefficients[50];
int count = 0;
if(fgets(line, LINE_SIZE, stdin) == NULL) {
printf("Chyba: Nepodarilo sa nacitat hodnotu x.\n");
return 1;
}
x = strtof(line, NULL);
while (fgets(line, LINE_SIZE, stdin) != NULL) {
if (strlen(line) == 1)
break;
float coef = strtof(line, NULL);
coefficients[count++] = coef;
}
if(count == 0){
printf("Chyba: Nepodarilo sa nacitat koeficienty.\n");
return 1;
}
float result = coefficients[0];
for (int i = 1; i < count; i++) {
result = result * x + coefficients[i];
}
printf("Vysledok je: %.2f\n", result);
return 0;
}