- #include<stdio.h>
- #include"0006_test.cpp"
- int sum(int i, int j, int N, int *P[MAXSIZE][MAXSIZE], int S, int hold[MAXSIZE][MAXSIZE]);
- int checker(int i, int j, int N, int S, int hold[MAXSIZE][MAXSIZE]);
- int equal_sum(int N, int *P[MAXSIZE][MAXSIZE], int S, int number[MAXSIZE][MAXSIZE])
- {
- if (sum(0, 0, N, P, S, number) == 1)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int sum(const int i, int j, int N, int *P[MAXSIZE][MAXSIZE], int S, int hold[MAXSIZE][MAXSIZE])
- {
- int a, y;
- int check = 0;
- int total = 0;
- for(a = 0; (*(P[i][j] + a) != 0) && (check == 0); a++)
- hold[i][j] = *(P[i][j] + a);
- total = 0;
- for (y = 0; y <= j; y++)
- {
- total += hold[i][y];
- }
- if(total <= S)
- {
- if(j < N - 1)
- {
- check = sum(i, j+1, N, P, S, hold);/*/
- }
- else
- {
- if (total == S)
- {
- if (i == N - 1)
- {
- check = checker(0, 0, N, S, hold);
- }
- else
- {
- check = sum(i+1, 0, N, P, S, hold);
- }
- };
- }
- }
- }/*for */
- return check;
- }
- int checker(int i, const int j, int N, int S, int hold[MAXSIZE][MAXSIZE])
- {
- int check = 0;
- int add = 0;
- for(i = 0; i < N; i++)
- {
- add += hold[i][j];
- }
- if (add == S)
- {
- if (j == N - 1)
- {
- check = 1;
- }
- else
- {
- check = checker (0, j+1, N, S, hold);
- }
- };
- return check;
- }
Raw Paste