Homework 4 (2)
// series 1 - 2 + 3 - 4 +......
#include <iostream>
using namespace std;
// Function to calculate sum
int solve_sum(int n)
{
// when n is odd
if (n % 2 == 1)
return (n + 1) / 2;
// when n is not odd
return -n / 2;
}
// Driver code
int main()
{
int n = 8;
cout << solve_sum(n);
return 0;