Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #ifndef DEBUG
- #define DEBUG(...) printf(__VA_ARGS__)
- #endif
- #define MAXN 100001
- int subsum(int *a, int n) {
- int p = 1;
- if (!n)
- {
- return 0;
- }
- if (n%2==1)
- {
- p = -1;
- }
- return (*a * p) + subsum(a+1, n-1);
- }
- int main() {
- int n, a[MAXN];
- scanf("%d", &n);
- for (int i = 0; i < n; ++i) {
- scanf("%d", &a[i]);
- }
- printf("%d\n", subsum(a, n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement