#include <stdio.h>
#include <stdlib.h>

void trim_out_of_range(void);
int shift_right(const int idx, const int sum = 0);
int shift_down(const int idx, const int sum = 0);

int *list;
int size;
int sum;

int main(void)
{
    printf("Enter n= "); scanf("%d", &size);

    list = (int *)malloc(sizeof(int) * size);
    for(int i = 0; i < size; i++)
    {
        printf("Enter list[%d]= ", i); scanf("%d", &list[i]);
    }

    printf("Enter k= "); scanf("%d", &sum);

    trim_out_of_range();
    printf("Result: %d\n", shift_right(size - 1));

    free(list);

    return 0;
}

void trim_out_of_range(void)
{
    for(int i = size - 1; i >= 0; i--)
        if(list[i] > sum)
        {
            for(int j = i; j < size; j++) list[j] = list[j + 1];
            size--;
        }
}

int shift_right(const int idx, const int sum)
{
    if(idx < 0 && sum == ::sum) return 1;
    if(idx < 0) return 0;

    return shift_right(idx - 1, sum + list[idx]) + shift_down(idx, sum);
}

int shift_down(const int idx, const int sum)
{
    if(idx - 1 < 0) return 0;
    return shift_right(idx - 1, sum);
}

#include <stdio.h>
#include <stdlib.h>

int *list;
int size;
int sum;

int main(void)
{
    size = 9;
    sum = 15;
    list = (int *)malloc(sizeof(int) * size);

    list[0] = 1;
    list[1] = 5;
    list[2] = 8;
    list[3] = 3;
    list[4] = 7;
    list[5] = 12;
    list[6] = 11;
    list[7] = 2;
    list[8] = 6;

    func(size - 1);

    free(list);

    return 0;
}

--- 
+++ 
@@ -1,5 +1,9 @@
 #include <stdio.h>
 #include <stdlib.h>
+
+void trim_out_of_range(void);
+int shift_right(const int idx, const int sum = 0);
+int shift_down(const int idx, const int sum = 0);
 
 int *list;
 int size;
@@ -7,23 +11,44 @@
 
 int main(void)
 {
-    size = 9;
-    sum = 15;
+    printf("Enter n= "); scanf("%d", &size);
+
     list = (int *)malloc(sizeof(int) * size);
+    for(int i = 0; i < size; i++)
+    {
+        printf("Enter list[%d]= ", i); scanf("%d", &list[i]);
+    }
 
-    list[0] = 1;
-    list[1] = 5;
-    list[2] = 8;
-    list[3] = 3;
-    list[4] = 7;
-    list[5] = 12;
-    list[6] = 11;
-    list[7] = 2;
-    list[8] = 6;
+    printf("Enter k= "); scanf("%d", &sum);
 
-    func(size - 1);
+    trim_out_of_range();
+    printf("Result: %d\n", shift_right(size - 1));
 
     free(list);
 
     return 0;
 }
+
+void trim_out_of_range(void)
+{
+    for(int i = size - 1; i >= 0; i--)
+        if(list[i] > sum)
+        {
+            for(int j = i; j < size; j++) list[j] = list[j + 1];
+            size--;
+        }
+}
+
+int shift_right(const int idx, const int sum)
+{
+    if(idx < 0 && sum == ::sum) return 1;
+    if(idx < 0) return 0;
+
+    return shift_right(idx - 1, sum + list[idx]) + shift_down(idx, sum);
+}
+
+int shift_down(const int idx, const int sum)
+{
+    if(idx - 1 < 0) return 0;
+    return shift_right(idx - 1, sum);
+}
Add solution of prob 2
