Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function called calcSum that will calculate and return the sum of a spec

ID: 3689517 • Letter: W

Question

Write a function called calcSum that will calculate and return the sum of a specific number of values in an array of integers. The function takes two arguments: an array of integers to be added and an integer that holds the number of values in the array to use when calculating the sum. It returns an integer: the sum of the specified number of values in the array. The function should execute a loop that runs "number of values in the array" number of times. Each iteration of the loop should add a value from the array to a running total (the sum). Once the loop is done executing, the running total (sum) should then be returned.

Explanation / Answer

int calcSum(int arr[],int num)

{ int i,sum=0;

for(i=0;i<num;i++)

{

sum=sum+arr[i];

}

return(sum);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote