#include #include void polValue(FILE* f, double *p, double *dp); int main() { FILE* in = fopen("input.txt", "r"); if (in == NULL) { perror("Could not open input file"); return (-1); } double p, dp; polValue(in, &p, &dp); fclose(in); FILE* out = fopen("output.txt", "w"); if (in == NULL) { perror("Could not open output file"); return (-1); } fprintf(out, "%f %f\n", p, dp); fclose(out); return 0; } void polValue(FILE* f, double *p, double *dp) { double x; if (fscanf(f, "%lf", &x) != 1) { fprintf(stderr, "Incorrect input file.\n"); exit(-1); } double pv = 0.; double dpv = 0.; double a; while (fscanf(f, "%lf", &a) == 1) { dpv = dpv * x + pv; pv = pv * x + a; } *p = pv; *dp = dpv; }