How to do something like this
for(int a = 0; a<2; a++){
for(int b = 0; b<2; b++){
for(int c = 0; c<2; c++){
for(int d = 0; d<2; d++){
n[a+b+c+d]=x[a]*y[b]*z[c]...
}}}}
But i have x [n]...
Recursively:
void do_sum(double *n, double *x, int limit, int index, double sum)
{
if (limit == 0)
n[index] = sum;
else
for (int a = 0; a<2; a++)
do_sum(n, x, limit-1, index+a, sum+x[a]);
}
To initiate the recursion, start with do_sum(n, x, max_n, 0, 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With