title: How to check if an integer is linear combination of elements in an array?
body: <p>How to check if an integer can be expressed as linear combination of elements in a given array of length n? Currently I can code for the specific case when n=2, but I don't know how to code when n is unknown.</p>
  
  <p>This is the function when n=2 (when there are only two elements in the array):</p>
  
  <pre><code>bool check(int array[], int n, int value){//n values in the array //    
  
    for (int i=1; i&lt;array[0]; i++){
       for (int j=1; j&lt;array[1]; j++){
          if ((i*array[0]+j*array[1])%value==0){
              printf("x=%d, y=%d, i=%d, j=%d\n", array[0], array[1], i, j);
              return 1;
          }
      }
      }
  return 0;
  }
  </code></pre>