X1658: Alternating Sum

Description

Write a recursive method int A(int n) such that:

A(n) = n - A(n - 1) for n >= 1

with initial values

  • A(0) = 0

Constraints

  • You must use a recursive function

Examples:

A(0) -> 0
A(1) -> 1
A(2) -> 1

Your Answer:

Feedback

Your feedback will appear here when you check your answer.