Median vs. Average, Arduino Calculations

Share on facebook
Share on google
Share on twitter
Share on linkedin
A VPN is an essential component of IT security, whether you’re just starting a business or are already up and running. Most business interactions and transactions happen online and VPN

If we want to average a set of numbers, we add them together, then divide by the number in the set.

150 + 200 + 0 = 350 / 3 = 116 Average

I’m using int and dropping the fractional parts. Use float if you need them.

But if we want the Median, which is the center, or middle number, we have to sort and compare each number to the others to get a list from high to low, and grab the center number. In this case, the Median is 150.

I’ve written a sketch that calculates both so you can compare your own numbers, and make it a much larger list:

int a[] = {150,200,0};
int n = 3;

a[] is your set of values

n is the number of values in the set

https://pastebin.com/Ge0pZGS2

More info on Mean, Median & Average – https://www.vocabulary.com/articles/chooseyourwords/mean-median-average/

Steve Spence

Steve Spence

Leave a Reply

Leave a Comment

Your email address will not be published. Required fields are marked *