computes the number of ways to partition n into the sum of positive integers c++
<p>I need to write function as part of assignment..
I need to compute the number of ways to partition n into the sum of positive integers and I can't use for while or goto</p>

<pre><code>/*
 * REQUIRES: n &gt; 0
 * EFFECTS: computes the number of ways to partition n into the sum of
 *          positive integers
 * MUST be tree recursive
 * Hint: Use a helper function that computes the number of ways to
 * partition n using a bounded subset of integers. Then use logic
 * similar to count_change() from lecture to divide partitions into
 * those that use a specific item and those that do not.
 */
int num_partitions(int n);
</code></pre>

<p>I figured a way to print them but unable to count it and my function also needed for loop. Here's function</p>

<pre><code>void print(int n, int * a) {
    int i ; 
    for (i = 0; i &lt;= n; i++) {
        printf("%d", a[i]); 
    }
    printf("\n"); 
}

int integerPartition(int n, int * a, int level,int c){
    int first; 
    int i; 
    if (n &lt; 1)
    {
        return c;    
    }
    a[level] = n;
    print(level, a);
    c++;
    first = (level == 0) ? 1 : a[level-1];
    for(i = first; i &lt;= n / 2; i++){
        a[level] = i; 
        integerPartition(n - i, a, level + 1,c);
    }
}
int num_partitions(int n){
    int * a = (int * ) malloc(sizeof(int) * n); 
    return integerPartition (n, a, 0,0);

}
</code></pre>

<p>please help...</p>

<p>here is the count change function</p>

<pre><code>int count_change(int amount, const int coins[], int num_coins) {

if (amount == 0) {

return 1;

} else if​ (amount &lt; 0 || num_coins &lt; 1) {

return 0;

} else {

return
count_change(amount - coins[num_coins - 1], coins, num_coins) +

count_change(amount, coins, num_coins - 1);
}

}
</code></pre>