Devise a function to count the sum of a series of integers 1…N, with alternating (+) and (-) operators, using the recursive method

Issue

This Content is from Stack Overflow. Question asked by topinfx

As per the title, I’ve been given this task to solve. While it is easy to do this using a traditional loop, I am still lost on how this could be achieved using recursion. Any help regarding this will be appreciated!

Here are the expected results:

Input: 4
Output: 4
Explanation: 1 + 2 - 3 + 4 = 4

Input 9 
Output: -3
Explanation: 1 + 2 - 3 + 4 - 5 + 6 - 7 + 8 - 9 = -3



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?