Question: Write a function named alternatingSum that takes a vector of integers, and returns the alternating sum of all elements in the vector. For example,
Write a function named alternatingSum that takes a vector of integers, and returns the alternating sum of all elements in the vector. For example, if alternatingSum is called with a vector numbers containing then it computes 1 3 2 5 3 1 5 11 20 1-3+2 5+3-1+5-11+ 20 = 11 Define your function alternatingSum using the prototype int alternatingSum (const vector & numbers);
Step by Step Solution
3.54 Rating (151 Votes )
There are 3 Steps involved in it
The function alternatingSum can be implemented in Python as follows Python def alternatingSumnumbers Computes the alternating sum of all elements in a ... View full answer
Get step-by-step solutions from verified subject matter experts
