[tex]E(n) = \left\{\begin{array}{ll} 0,\ daca\ n=0\\ E(n-1)+n, \ daca\ n - impar\\ E(n-1)-n, \ daca\ n - par\end{array} \right{, \forall n \in \mathbb{N}}[/tex]
#include <iostream>
using namespace std;
int fct(int n) {
if (n == 0) return 0;
else if (n % 2) return fct(n - 1) + n;
else return fct(n - 1) - n;
}
int main() {
unsigned n;
cout << "Introduceti n : ";
cin >> n;
cout << "E(" << n << ") = " << fct(n);
}