Deliverable is to design an algorithm for a function that accepts an integer arr
ID: 3555618 • Letter: D
Question
Deliverable is to design an algorithm for a function that accepts an integer array as an argument and returns the total of values in the array. I need help to validate my understanding. this is my algorithm
// The First line in the program should be the function header
// What should be in the Function Header?
// enter the word Function followed by the DataType, Function Name, and (ParameterList)
Function(int array[ ], int size)
Integer total = 0
for i<-1 to size
sum<-sum+array[i]
return total
End function
Explanation / Answer
As we need to total the elements in the array we loop the array from 1st element to last and add each elemnt to the variable total and return total at the end. Please see below changes in bold
Function(int array[ ], int size)
Integer total = 0
for i=1 to size
total<-total+array[i]
return total
End function
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.