Averages/Root mean square

import "std/math.zc"

fn rms(a: f64*, len: const int) -> f64 {
    let sum = 0.0;
    for i in 0..len { sum += a[i] * a[i]; }
    return Math::sqrt(sum / len);
}

fn main() {
    let a = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0];
    println "{rms(a, 10):0.16f}";
}

Output:

6.2048368229954285

Attribution: This is a community solution for the Rosetta Code task Averages/Root mean square in Zen C.

This article uses material from the Rosetta Code article Averages/Root mean square, which is released under the GNU Free Documentation License 1.3. A list of the original authors can be found in the page history.