Dynamic Programming - Minimum number of coins in C : <p>I have looked through various questions on the site and I haven't managed to find anything which implements this by the following reasoning (so I hope this isn't a duplicate).</p>

<p>The problem I'm trying to solve via a C program is the following:</p>

<blockquote>
  <p>As the programmer of a vending machine controller your are required to compute the minimum number of coins that make up the required change to give back to customers. An efficient solution to this problem takes a dynamic programming approach, starting off computing the number of coins required for a 1 cent change, then for 2 cents, then for 3 cents, until reaching the required change and each time making use of the prior computed number of coins. Write a program containing the function <code>ComputeChange()</code>, that takes a list of valid coins and the required change. This program should repeatedly ask for the required change from the console and call <code>ComputeChange()</code> accordingly. It should also make use of “caching”, where any previously computed intermediate values are retained for subsequent look-up.</p>
</blockquote>

<p>After looking around online to find how others have solved it, I found the following example applied with pennies, nickels and dimes:</p>

<p><a href="https://i.stack.imgur.com/dYlPp.png" rel="noreferrer"><img src="https://i.stack.imgur.com/dYlPp.png" alt="enter image description here"></a></p>

<p>Which I tried to base my code upon. But first of all, my code isn't halting, and secondly, I'm not sure if I'm incorporating the <em>caching</em> element mentioned in the rubric above. (I'm not really sure how I need to go about that part). </p>

<p>Can anyone help find the flaws in my code?</p>

<pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
#include &lt;limits.h&gt;

int computeChange(int[],int,int);
int min(int[],int);

int main(){
    int cur[]={1,2,5,10,20,50,100,200};
    int n = sizeof(cur)/sizeof(int);
    int v;

    printf("Enter a value in euro cents: ");
    scanf("%d", &amp;v);

    printf("The minimum number of euro coins required is %d", computeChange(cur, v, n));

    return 0;
}

int computeChange(int cur[], int v, int n){
    if(v &lt; 0)
        return -1;
    else if(v == 0)
        return 0;
    else{
        int possible_mins[n], i;
        for(i = 0; i &lt; n; i++){
            possible_mins[i]=computeChange(cur, v-cur[i], n);
        }
        return 1+min(possible_mins, n);
    };
}

int min(int a[], int n){
    int min = INT_MAX, i;
    for(i = 0; i &lt; n; i++){
        if((i&gt;=0) &amp;&amp; (a[i]&lt; min))
            min = a[i];
    }
    return min;
}
</code></pre>

<p>Any assistance will be greatly appreciated.</p>
