Advertisement
KgCro

rekurzivno_oduzbrajanje - G3 2018/2020 K2

Jun 3rd, 2020
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5.  
  6. #ifndef DEBUG
  7. #define DEBUG(...) printf(__VA_ARGS__)
  8. #endif
  9.  
  10. #define MAXN 100001
  11.  
  12. int subsum(int *a, int n) {
  13.     int p = 1;
  14.  
  15.     if (!n)
  16.     {
  17.         return 0;
  18.     }
  19.  
  20.     if (n%2==1)
  21.     {
  22.         p = -1;
  23.     }
  24.     return (*a * p) + subsum(a+1, n-1);
  25. }
  26.  
  27. int main() {
  28.   int n, a[MAXN];
  29.   scanf("%d", &n);
  30.   for (int i = 0; i < n; ++i) {
  31.     scanf("%d", &a[i]);
  32.   }
  33.   printf("%d\n", subsum(a, n));
  34.   return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement