Question: Sum Create a function that calculates the sum of all numbers of an integer array. int sum ( const int array [ ] , const

Sum
Create a function that calculates the sum of all numbers of an integer array.
int sum(const int array[], const int size)
Example of pseudocode
function sum
// INPUT: integer array, size
// OUTPUT: sum
sum <--0
for i from 0 to size-1
sum <-- sum + array[i]
end for
return sum
Recursive sum
Create a function that calculates the sum of all numbers of an integer array recursively.
int recursiveSum(const int array[], const int size, const int position)
Example of pseudocode
function recursiveSum
// INPUT: integer array, size, position (to analyze)
// OUTPUT: partial sum
if position >= size
return 0
else
return array[position]+ recursiveSum(array,size,position+1)
end if
Recursive Max
Create a function that determine recursively the maximum value of the numbers of an integer array.
int recursiveMax(const int array[], const int size, const int position)
Example of pseudocode
function recursiveMax
// INPUT: integer array, size, position (to analyze)
// OUTPUT: partial max
if position >= size
return INT_MIN
else
partialMax <-- recursiveMax(array,size,position+1)
if array[position]> partialMax
return array[position]
else
return partialMax
end if
end if
See INT_MIN definition.
Recursive Min
Create a function that determine recursively the minimum value of the numbers of an integer array.
int recursiveMin(const int array[], const int size, const int position)
In the main function
Create an integer array of at least 10 elements, and display its elements.
Test the four functions using that array and display the results results.
Example of expected output
Recursive functions!
--------------------
[83484393218547604]
Sum: 322
Recursive sum: 322
Recursive max: 84
Recursive min: 0Sum
Create a function that calculates the sum of all numbers of an integer array.
int sum(const int array[], const int size)
Example of pseudocode
function sum
// INPUT: integer array, size
// OUTPUT: sum
sum <--0
for i from 0 to size-1
sum <-- sum + array[i]
end for
return sum
Recursive sum
Create a function that calculates the sum of all numbers of an integer array recursively.
int recursiveSum(const int array[], const int size, const int position)
Example of pseudocode
function recursiveSum
// INPUT: integer array, size, position (to analyze)
// OUTPUT: partial sum
if position >= size
return 0
else
return array[position]+ recursiveSum(array,size,position+1)
end if
Recursive Max
Create a function that determine recursively the maximum value of the numbers of an integer array.
int recursiveMax(const int array[], const int size, const int position)
Example of pseudocode
function recursiveMax
// INPUT: integer array, size, position (to analyze)
// OUTPUT: partial max
if position >= size
return INT_MIN
else
partialMax <-- recursiveMax(array,size,position+1)
if array[position]> partialMax
return array[position]
else
return partialMax
end if
end if
See INT_MIN definition.
Recursive Min
Create a function that determine recursively the minimum value of the numbers of an integer array.
int recursiveMin(const int array[], const int size, const int position)
In the main function
Create an integer array of at least 10 elements, and display its elements.
Test the four functions using that array and display the results results.
Example of expected output
Recursive functions!
--------------------
[83484393218547604]
Sum: 322
Recursive sum: 322
Recursive max: 84
Recursive min: 0

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 Accounting Questions!