simpleAlternatedSum

Implement a RECURSIVE function that, given a positive natural nn, returns the simple altenated sum 12+34++(1)n+1n1-2+3-4+\ldots+(-1)^{n+1}\cdot n. This is the header:

// Pre: n >= 1
// Post: Returns 1-2+3-4+...+(-1)^(n+1)*n
int simpleAlternatedSum(int n);

Observation

You only need to submit the required procedure; your main program will be ignored.

Observation

Note that we are requesting a RECURSIVE solution.

Problem information

Author: PRO1

Generation: 2026-01-25T21:40:46.879Z

© Jutge.org, 2006–2026.
https://jutge.org