MHB Solve Computing an Average Problem | Help

  • Thread starter Thread starter mjcruzz
  • Start date Start date
  • Tags Tags
    Average Computing
AI Thread 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: 124
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top