#include #include #include double meanGeom(FILE* f); int main() { FILE* in = fopen("input.txt", "r"); if (in == NULL) { perror("Could not open input file"); return (-1); } double m = meanGeom(in); fclose(in); FILE* out = fopen("output.txt", "w"); if (in == NULL) { perror("Could not open output file"); return (-1); } fprintf(out, "%f\n", m); fclose(out); return 0; } double meanGeom(FILE* f) { int n = 0; double prod = 1.; double a; while (fscanf(f, "%lf", &a) == 1) { if (a < 0.) { fprintf(stderr, "Incorrect input file.\n"); exit(-1); } prod *= a; ++n; } if (n == 0) { fprintf(stderr, "Incorrect input file.\n"); exit(-1); } return pow(prod, 1. / (double) n); }