Course of Raku / Advanced / Operators / Meta-operators / Exercises

Average of an array

Problem

Write a program that prints the average (the arithmetic mean) of an array of numbers. Use a reduction meta-operator to add the values up.

The input data are hard-coded in the program, for example:

my @data = 10, 20, 30, 40;

Example

The program prints the mean of the elements of @data:

25

Solution

See the solution

Course navigation

Quiz — Hyper and cross   |   Solution: Average of an array