Answer to Question #275198 in C for Mr Z

Question #275198

Spirit Level, Thermometer, Countdown Timer:

skeleton functions will be provided to you to complete the code within them. 3.1 Spirit level Firstly, you will need to write a function: int average(int *array, int nLen);


which returns the average value of an array of integer values. (To prevent overflow, it is suggested to use a long internal variable).


The Spirit Level function will run a loop. For each iteration, the Z-component of gravitational acceleration will be sampled four times at 50ms intervals and stored in a suitably sized array.


Using the average()function you have written, determine the average value of the 4 Zvalue samples and analyze it. The green LED should be illuminated if the board is flat. The yellow LED should be illuminated if the board is at a slight angle. The red LED should be illuminated if the board is at a steep angle. The loop can be exited by pressing and holding S2. 


1
Expert's answer
2021-12-05T13:07:52-0500
int average(int *array, int nLen) {
 int total = 0;
 for (int i = 0; i < nLen; i++) total += array[i];
 return total / nLen;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS