pvjc25/du2/program.c

41 lines
824 B
C
Raw Normal View History

2025-03-06 23:16:39 +00:00
#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;
2025-03-06 23:22:43 +00:00
if(fgets(line, LINE_SIZE, stdin) == NULL){
2025-03-06 23:16:39 +00:00
printf("Chyba: Nepodarilo sa nacitat hodnotu x.\n");
return 1;
}
x = strtof(line, NULL);
2025-03-06 23:22:43 +00:00
while (fgets(line, LINE_SIZE, stdin) != NULL){
2025-03-06 23:16:39 +00:00
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];
2025-03-06 23:22:43 +00:00
for (int i = 1; i < count; i++){
2025-03-06 23:16:39 +00:00
result = result * x + coefficients[i];
}
printf("Vysledok je: %.2f\n", result);
return 0;
}