pvjc24/cv3/program.c
2024-03-08 00:44:26 +01:00

45 lines
1.1 KiB
C

#include <stdio.h>
#define SIZE 100
int main() {
double coefs[SIZE] = {0.0};
double x = 1.0; // initialize x to 1.0
double input = 0.0;
int count = 0;
int length = 0;
double result = 0.0;
while (count < SIZE) {
if (scanf("%lf", &input) != 1) {
if (scanf("%c", &input) == 1) {
if (count == 0){
printf("Nepodarilo sa nacitat zaklad x\n");
return 0;
}
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", count);
return 0;
}
break;
}
if (count == 0) {
x = input; // use the first input as the base value x
} else {
coefs[count-1] = input; // store the coefficient in the array
length = count;
}
count++;
}
length = count; // update the length after reading the last coefficient
for (int i = 1; i < length; i ++){
result = result * x + coefs[i-1]; // use the correct index for the coefficient array
}
printf("Vysledok je: %.2lf\n", result);
return 0;
}