That code doesn't compile:
fprintf(doc," %f %f %f \n\n",y,mean_r,);
You have specified three "%f" parameters in the format string but provided two, and have an empty parameter at the end - you'll get an error for the ",)" part, and a problem when it tries to execute if you remove the ",".
Try resetting
sum_r
after each
STEPS
iteration.
The way I'd do it is to write a function which generated a set of random numbers and returned the average.
Then call that repeatedly for each value of
y
and print the result.