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);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.