Task of Challenge #11/54
Calculate the average of the numbers in an array of numbers. The array: [2, 5, 17, 81, 9].
How to calculate an average
A calculated “central” value of a set of numbers.
To calculate it: add up all the numbers, then divide by how many numbers there are.
Example: what is the average of 2, 7 and 9?
Add the numbers: 2 + 7 + 9 = 18
Divide by how many numbers (i.e. we added 3 numbers): 18 ÷ 3 = 6
So the average is 6
(Also called the Arithmetic Mean.)
Accomplishing our Goal
To accomplish our task, we create a function called
averageArray() and pass in our array.
We need to get the length of the array for our for-loop. Creating a sum and then dividing by the length gets our average.
Just return the number and print it to the console, and you are done!
Follow me on Instagram and don’t miss the latest Challenge!
Become a bullet proof developer and seek my coding adventures on Udemy
Don’t miss two of my most read Medium Articles
5 Methods that drastically shorten drastically your Code in C# 8.0 by @ArnoldAbrahamP1 https://t.co/UlTW3H7bD9— Kumpulin1 (@kumpulin1) May 5, 2021