Andziev

Сума од суми

Nov 29th, 2016
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int sum (int array[], int N) {
  4.     if(N < 0) return 0;
  5.     return array[N] + sum (array, N - 1);
  6. }
  7. int main () {
  8.  
  9.     int N, s = 0;
  10.     scanf("%d",&N);
  11.     int array[N];
  12.     for(int i=0; i<N; i++) {
  13.         scanf("%d",&array[i]);
  14.         array [i] = array[i] > 0 ? array[i] : 0;
  15.     }
  16.     for(int i=0; i<N; i++) {
  17.         s = 0;
  18.         for(int j=0; j<i; j++)
  19.             s += sum (array,j);
  20.         printf("%d\n",s);
  21.     }      
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment