CPP   22
int dum
Guest on 20th September 2023 12:10:14 AM


  1. #include<stdio.h>
  2. #include"0006_test.cpp"
  3.  
  4. int sum(int i, int j, int N, int *P[MAXSIZE][MAXSIZE], int S, int hold[MAXSIZE][MAXSIZE]);
  5. int checker(int i, int j, int N, int S, int hold[MAXSIZE][MAXSIZE]);
  6.  
  7. int equal_sum(int N, int *P[MAXSIZE][MAXSIZE], int S, int number[MAXSIZE][MAXSIZE])
  8. {  
  9.         if (sum(0, 0, N, P, S, number) == 1)
  10.         {
  11.            return 1;
  12.         }
  13.         else
  14.         {
  15.              return 0;
  16.         }
  17. }
  18.  
  19. int sum(const int i, int j, int N, int *P[MAXSIZE][MAXSIZE], int S, int hold[MAXSIZE][MAXSIZE])
  20. {
  21.     int a, y;
  22.     int check = 0;
  23.     int total = 0;
  24.    
  25.     for(a = 0; (*(P[i][j] + a) != 0) && (check == 0); a++)
  26.           hold[i][j] = *(P[i][j] + a);
  27.  
  28.           total = 0;
  29.           for (y = 0; y <= j; y++)
  30.           {    
  31.           total += hold[i][y];
  32.           }
  33.          
  34.           if(total <= S)
  35.           {
  36.                    if(j < N - 1)
  37.                    {
  38.                         check = sum(i, j+1, N, P, S, hold);/*/
  39.                    }
  40.                    else  
  41.                    {
  42.                         if (total == S)
  43.                         {
  44.                            if (i == N - 1)
  45.                            {
  46.                                 check = checker(0, 0, N, S, hold);
  47. }
  48.                            else
  49.                            {
  50.                                 check = sum(i+1, 0, N, P, S, hold);
  51.                            }
  52.                      
  53.                         };
  54.                    }
  55.           }
  56.     }/*for */
  57.    
  58.     return check;
  59. }
  60.  
  61. int checker(int i, const int j, int N, int S, int hold[MAXSIZE][MAXSIZE])
  62. {  
  63.     int check = 0;
  64.     int add = 0;
  65.    
  66.     for(i = 0; i < N; i++)
  67.     {
  68.           add += hold[i][j];
  69.     }
  70.    
  71.     if (add == S)
  72.     {
  73.             if (j == N - 1)
  74.             {
  75.                check = 1;
  76.             }
  77.             else
  78.             {
  79.                  check = checker (0, j+1, N, S, hold);
  80.             }
  81.     };
  82.     return check;
  83. }

Raw Paste

Login or Register to edit or fork this paste. It's free.