這題簡單的我來
另外兩題難的要靠別的高手了
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int x_sum(int arr[], int len) {
int set[MAX];
int m, n, position;
int i;
int answer = 0;
m = len;
n = 3;
for(i = 0; i < n; i++)
set[i] = i + 1;
int check = 0;
for(i = 0; i < n; i++) {
printf("%d ", arr[set[i]-1]);
check = check + arr[set[i]-1];
}
if (check==0) { answer = answer + 1; }
printf(" sum = %d\n", check);
position = n - 1;
while(1) {
if(set[n-1] == m)
position--;
else
position = n - 1;
set[position]++;
for(i = position + 1; i < n; i++)
set[i] = set[i-1] + 1;
check = 0;
for(i = 0; i < n; i++) {
printf("%d ", arr[set[i]-1]);
check = check + arr[set[i]-1];
}
if (check==0) { answer = answer + 1; }
printf(" sum = %d\n", check);
if(set[0] >= m - n + 1)
break;
}
return answer;
}
int main() {
int arr[9] = {1,2,3,4,5,-4,0,-2,-1};
int answer = x_sum(arr, 9);
printf("answer=%d\n", answer);
return 0;
}