...
/Example 43: Calculate Sum, Average, and Standard Deviation
Example 43: Calculate Sum, Average, and Standard Deviation
Learn how to calculate the sum, average, and standard deviation of the given numbers using pointers.
We'll cover the following...
Problem
Write a function that calculates the sum, average, and standard deviation of the given numbers. It receives five integers along with three pointers to store the results as parameters.
Example
| Input (n1, n2, n3, n4, n5) | Output(Sum, Average, Standard Deviation) |
|---|---|
| 4, 5, 3, 7, 9 | 28.000000, 5.600000, 2.408319 |
| 4, -2, 8, -4, 3 | 9.000000, 1.800000, 4.816638 |
Try it yourself
Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.
Solution
Given below is our recommended way to approach this problem.
Explanation
The function cal_sasd() takes in five numbers as its parameters. It then calculates their sum, average, and standard deviation. Next, it assigns all the results to their respective pointers and then prints the pointer values on the console.
The formula to calculate standard deviation is:
...