Programming Fundamentals
Download array_sum_prod.c here
Or, copy these file(s) to your CSE account using the following command:
1511 fetch-activity array_sum_prod
Your task is to add code to this function in array_sum_prod.c:
// Calculates the sum and product of the array nums.
// Actually modifies the variables that *sum and *product are pointing to
void array_sum_prod(int length, int nums[length], int *sum, int *product) {
// TODO: Complete this function
}
The above file array_sum_prod.c
contains a function
array_sum_prod
, which should find the sum and the product of the
values stored in the array. It should write these values into the integers
referenced by the pointers in the input to the function.
Unfortunately, the provided function doesn't actually work. For this lab exercise, your task is to complete this function.
The file also contains a main function which you can use to help test
your array_sum_prod
function. It has two simple test cases.
This main function will not be marked -- you must write all of your code
in the array_sum_prod
function.
You may modify the main function if you wish (e.g. to add further tests),
but only the array_sum_prod
function will be marked.
Examples
dcc -o array_sum_prod array_sum_prod.c ./array_sum_prod Sum: 20, Product: 360 Sum: 10, Product: 24
Assumptions/Restrictions/Clarifications
- You will not be given an empty array as input, you can assume that you have at least 1 value.