Your issue is with your loop calculating and printing the same value because of how the value is printed using 'fprintf'. The format specifier '%lg' is used for reading a double value with 'fscanf', but when you print with 'fprintf', you should just use the variable 'sum' without the '&' operator -
fprintf(fileout, "%lg\n", sum);
You are also trying to scale the 'var' value using 'maxy' and '65536.0', but you're assigning the scaled value directly to 'sum' in each iteration of your loop. This means that in each iteration, 'sum' is being overwritten with a new value. To accumulate the scaled values, you should add the scaled value to 'sum' instead of assigning it -
sum += var * (maxy / 65536.0);
Your loop should look like this -
for (c = 0; c <= n; c = c + 1)
{
fscanf(filein, "%lg", &var);
sum += var * (maxy / 65536.0);
fprintf(fileout, "%lg\n", sum);
}