Averages/Root mean square: Difference between revisions

→‎{{header|C}}: When reverting changes for functional equivalence, it's probably polite to explain why, and note alternatives for other visitors.
m (→‎{{header|Java}}: ++ is nicer, how was the output wrong?)
(→‎{{header|C}}: When reverting changes for functional equivalence, it's probably polite to explain why, and note alternatives for other visitors.)
Line 138:
double sum = 0.0;
for(i = 0; i < n; i++)
// While there is a pow() function in stdlib, when
// simply squaring a number, multiplying it by itself
// is simpler, and likely more efficient.
sum += v[i] * v[i];
return sqrt(sum / n);
}
 
// Current C compilers do not require arguments to main().
// (Would someone care to fill in the specifics for an
// unused-argument case for K&R, C89 and C99, explicitly?)
int main()
{
double v[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
printf("%f\n", rms(v, sizeof(v)/sizeof(double)));
 
// Standard says we can return EXIT_SUCCESS or 0 here,
// and the compiler must provide the same resulting
// behavior.
return 0;
}</lang>