Averages/Pythagorean means: Difference between revisions
Content added Content deleted
m (→Three applicatively defined functions: liftA2 -> ((.) ... <*>)) |
(Added a V implementation) |
||
Line 3,350: | Line 3,350: | ||
Geometric mean 4.52872868811677 |
Geometric mean 4.52872868811677 |
||
Harmonic mean 3.41417152147406</pre> |
Harmonic mean 3.41417152147406</pre> |
||
=={{header|Vlang}}== |
|||
<lang vlang>import ( |
|||
arrays |
|||
math |
|||
) |
|||
fn main() { |
|||
mut sum := 0.0 |
|||
mut prod :=1.0 |
|||
mut recip_sum := 0.0 |
|||
n := 10.0 |
|||
for val in arrays.range<int>(1, n+1) { |
|||
sum += val |
|||
prod *= val |
|||
recip_sum = recip_sum + (1.0/val) |
|||
} |
|||
a := sum / n |
|||
g := math.pow(prod, (1.0/n)) |
|||
h := n / recip_sum |
|||
result := 'Arithmetic Mean: ${a : 3.2f} \nGeometric Mean: ${g : 3.2f}\nHarmonic Mean: ${h : 3.2f}' |
|||
println(result) |
|||
x := if a >= g && g >= h {"Yes"} else {"Nope"} |
|||
println('Is A >= G >= H? $x') |
|||
}</lang> |
|||
{{out}} |
|||
<pre>Arithmetic Mean: 5.50 |
|||
Geometric Mean: 4.53 |
|||
Harmonic Mean: 3.41 |
|||
Is A >= G >= H? Yes</pre> |
|||
=={{header|XPL0}}== |
=={{header|XPL0}}== |