6.5: Math Statistics with Arrays
- Page ID
Statistics is a branch of mathematics dealing with the collection, organization, analysis, interpretation, and presentation of data. Common statistical methods include mean (or average) and standard deviation.
Arrays are an important complex data type used in almost all programming. We continue to concentrate on simple one dimension arrays also called a list. Most programmers develop a series of user-defined specific task functions that can be used with an array for normal processing. These functions are usually passed the array along with the number of elements within the array. Some functions also pass another piece of data needed for that particular functions task.
This module covers the totaling of the members of an integer array member. The Latin name for totaling is summa, sometimes shortened to the word sum. In the example below, the sum function totals the array passed to it. Other mathematical functions often associated with statistics such as: average, count, minimum, maximum, standard deviation, etc. are often developed for processing arrays.
Function Main Declare Integer Array ages Declare Integer total Assign ages = [49, 48, 26, 19, 16] Assign total = sum(ages) Output "Total age is: " & total End Function sum (Integer Array array) Declare Integer total Declare Integer index Assign total = 0 For index = 0 to Size(array) - 1 Assign total = total + array[index] End Return Integer total
Total age is: 158
- Latin for summa or a total.