up to all and any numbers within a given range. For example, given a range of 4-9, your function must print out the fact that 5=2+3, 6=1+2+3, 7=3+4, 9=2+3+4, 9=4+5.
{{{
int min=4;
int max=9;
int idx1=1;//pointer 1 position
int idx2=2;//pointer 2 position
foo(int idx1, int idx2)
{
if(idx2>ceiling(max/2)||idx1>idx2)
return;
sum=sum_up(idx1…idx2);
if(sum
else if(sum>max)
foo(idx1++,idx2);
else //sum is between min and max
{
print(idx1...idx2);
foo(idx1++,idx2);
foo(idx1,idx2++);
}
}
}}}
No comments:
Post a Comment