Advertisement
Guest User

rozne_podzniory

a guest
Dec 6th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int zlicz(int *A, int n, int S)
  4. {
  5.     if(S == 0) return 1;
  6.     int i = n - 1, count = 0;
  7.  
  8.     while(i > -1 && A[i] > S) --i;
  9.     for(;i > -1; --i) count += zlicz(A, i, S - A[i]);
  10.  
  11.     if(A[0] == 0) count *= 2;
  12.     return count;
  13. }
  14.  
  15.  
  16. int main(void)
  17. {
  18.     int A[8] = {0, 1, 2, 3, 4, 5, 6, 7};
  19.     int a = zlicz(A, 8, 7);
  20.     int b = zlicz(A + 1, 7, 7);
  21.     printf("a wynosi %d\n", a);
  22.     printf("b wynosi %d\n", b);
  23.  
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement