MHB Solve Computing an Average Problem | Help

  • Thread starter Thread starter mjcruzz
  • Start date Start date
  • Tags Tags
    Average Computing
Click For Summary
To solve the average of three numbers a, b, and c, use the formula (a + b + c) / 3, as demonstrated with the example (3 + 4 + 8) / 3 = 5. For a general case with n numbers in an array, the average can be calculated by initializing a sum variable N to 0 and iterating through the array to accumulate the total. After the loop, the average is obtained by dividing the total sum N by n. Specifically, for n = 3, the process involves adding each element of the array to N and then dividing by 3. This method effectively calculates the average for any set of numbers.
mjcruzz
Messages
1
Reaction score
0
I can't seem to understand how to solve this problem. Please help
 

Attachments

  • Screen Shot 2021-01-30 at 8.20.30 PM.png
    Screen Shot 2021-01-30 at 8.20.30 PM.png
    205.7 KB · Views: 131
Technology news on Phys.org
The average of 3 numbers, a, b, and c, is [math]\frac{a+ b+ c}{3}[/math]. With the given example (3+ 4+ 8)/3= 15/3= 5.

You need "avg_sales= (numsales1+ numsales2+ numsales3)/3"
 
More generally, if you have n numbers, given as an array, num, and want to calculate their average it is
N= 0
for (i= 0; i< n; i++)
N= N+ num
Average= N/n;

In the case that n= 3, N would start at 0, after the i= 0 loop, N= 0+ num[0]= num[0], after the i= 1 loop, N= num[0]+ num[1], and after the i= 2 loop, N= (num[0]+ num[1])= num[2]= num[0]+ num[1]+ num[2]. The loop stops there because i= 3 does not satify "i< 3", and then Average= (num[0]+ num[1]+ num[2])/3.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 102 ·
4
Replies
102
Views
1K
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
940
Replies
29
Views
5K
Replies
15
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
3
Views
2K