Question: Write a function called sumAndAverage. It should take in an array of numbers and return the sum and average of the array in that order.

Write a function called sumAndAverage. It should take in an array of numbers and return the sum and average of the array in that order. For example:

[s a] = sumAndAverage([3 2 3 2]) %should return 10 and 2.5

[s a] = sumAndAverage([5 -5 2 8 0]) %should return 10 and 2

[s a] = sumAndAverage([]) %should return 0 and 0

You can use Built-in functions.

Create a vector, then invoke your function like this:

>>Arr=[3 2 3 2]

>>[s a]=sumAndAverage(Arr)

Note: the function has only one parameter. It is a vector

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!