2024-02-29 13:23:40 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2024-03-04 13:48:32 +00:00
|
|
|
#define SIZE 100
|
2024-02-29 13:23:40 +00:00
|
|
|
|
|
|
|
int main() {
|
2024-03-04 13:44:02 +00:00
|
|
|
double coefs[SIZE] = {0.0};
|
2024-03-07 23:44:26 +00:00
|
|
|
double x = 1.0; // initialize x to 1.0
|
2024-03-05 10:46:20 +00:00
|
|
|
double input = 0.0;
|
2024-03-07 13:24:52 +00:00
|
|
|
int count = 0;
|
2024-03-04 13:40:37 +00:00
|
|
|
int length = 0;
|
|
|
|
double result = 0.0;
|
2024-03-04 12:55:19 +00:00
|
|
|
|
2024-03-07 13:25:35 +00:00
|
|
|
while (count < SIZE) {
|
2024-03-07 13:13:02 +00:00
|
|
|
if (scanf("%lf", &input) != 1) {
|
2024-03-07 12:20:01 +00:00
|
|
|
if (scanf("%c", &input) == 1) {
|
2024-03-07 13:25:35 +00:00
|
|
|
if (count == 0){
|
|
|
|
printf("Nepodarilo sa nacitat zaklad x\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-03-07 12:21:47 +00:00
|
|
|
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", count);
|
2024-03-07 12:19:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2024-03-07 13:25:35 +00:00
|
|
|
|
2024-03-07 23:44:26 +00:00
|
|
|
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;
|
|
|
|
}
|
2024-03-05 10:38:40 +00:00
|
|
|
count++;
|
2024-03-05 09:51:11 +00:00
|
|
|
}
|
2024-03-05 09:41:49 +00:00
|
|
|
|
2024-03-07 23:44:26 +00:00
|
|
|
length = count; // update the length after reading the last coefficient
|
2024-03-04 13:14:10 +00:00
|
|
|
|
2024-03-05 10:09:13 +00:00
|
|
|
for (int i = 1; i < length; i ++){
|
2024-03-07 23:44:26 +00:00
|
|
|
result = result * x + coefs[i-1]; // use the correct index for the coefficient array
|
2024-03-04 13:14:10 +00:00
|
|
|
}
|
|
|
|
|
2024-03-04 13:41:35 +00:00
|
|
|
printf("Vysledok je: %.2lf\n", result);
|
2024-02-29 13:23:40 +00:00
|
|
|
|
|
|
|
return 0;
|
2024-03-05 10:09:13 +00:00
|
|
|
}
|