twenty seven functions you can write that deal with arrays Solution

his is going to be a create your own assignment to get more practice with arrays. Listed below are twenty seven functions you can write that deal with arrays. Listed next to each function is a number of points each is worth in parenthesis. You must choose enough functions to add up to 15 points! You can choose to do more, but you will only get up to 15 points for this assignment.

For each of the following:

-You must create a function that carries out the desired action. Please keep in mind that printing should not be done in your functions!

-You should provide enough code in main to test each of your functions. You may use prepopulated arrays in main to pass into each of your functions, and you can print them out in main (or write an array printing function!)

Anyone who successfully completes and demonstrates ALL 27 functions will receive 15 extra credit points on this assignment (30/15).



1. (1) Subtract two arrays, store the result in a third array.

2. (1) Multiply two arrays, store the result in a third array.

3. (1) Divide two arrays, store the result in a third array.

4. (2) Add two 2D arrays, store the result in a third 2D array.

5. (2) Subtract two 2D arrays, store the result in a third 2D array.

6. (2) Multiply two 2D arrays, store the result in a third 2D array.

7. (2) Divide two 2D arrays, store the result in a third array.

8. (1) Average all the elements in an array.

9. (2) Average all the elements in a 2D array.

10. (3) Reverse the values in an array.

11. (4) Transpose a 2D array. (Rows become columns, columns become rows)

12. (3) Compress an array by averaging pairs of elements. For example, compressing array [1, 3, 8, 7, 5] produces array [2, 7.5, 5]

13. (2) Produce the sum of the elements on the main diagonal of a square array.

14. (2) Produce the product of the elements on the main diagonal of a square array.




15. (2) Find the minimum element in a 2D array.

16. (2) Find the maximum element in a 2D array.



17. (3) Shift an array left or right by a number of positions. Elements shifted out are lost. Elements shifted in are zeros. For example, given array [2, 4, 6, 8, 9] shifted right by 2 produces array [0, 0, 2, 4, 6]. Shifting the original array left 1 produces array [4, 6, 8, 9, 0].


18. (2) A 2D array exhibits Row Magic (every row has the same sum) (Return 1 or 0 for yes or no)

19. (2) A 2D array exhibits Column Magic (every column has the same sum) (Return 1 or 0 for yes or no)


Assignments Page 1


1. (3) Insert an element in an array at a given position, and shift elements down. The last element will 'fall off' the array. For example, given array [3, 4, 6, 7, 8] Insert 1 at index 2 results in array [3, 4, 1, 6, 7].
Powered by