I have 10 text files containing one column of 1,-1,0. I want to set a combination which sum the elements of each file.
For example, if I want to see all the combinations of 2 files among 10 files, I would create the 2 loops below: double sum;
for(int i;i=0;i<n;i++){
for(int j;j=i;j<n;j++){
sum += x[i]+x[j];
}
}
Another example, if I want to see all the combinations of 3 files among 10 files, I would create the 3 loops below:
for(int i;i=0;i<n;i++){
for(int j;j=i;j<n;j++){
for(int k;k=j;k<n;k++)
sum += x[i]+x[j]+x[k];
}
}
}
and so on, if I want to see the combinations x files among 10 files, I would create x loops.
My question is: I am looking for an algorithm which determines the number of loops by choosing x. If x=2, then I create 2 loops, if x=3, then I create 3 loops, if x=4, then I create 4 loops, ... or may be there is another way. Many thanks