What I want to code:
1.Given:
-A range of integers iRange from 1 up to iRange
-A desired number of combinations
2.Find the # of all possible combinations and print it out.

For example:
Given: iRange = 5 and n = 3
# of combinations = iRange! / ((iRange!-n!)*n!) = 5! / (5-3)! * 3! = 10 combinations and output:
123
124
125
134
135
142
145
234
245
345
OR another example:
Given: iRange = 4 and n = 2
# of combinations = iRange! / ((iRange!-n!)*n!) = 4! / (4-2)! * 2! = 6 combinations and output:
12
13
14
23
24
34

My Code so far:

``````#include <iostream>
using namespace std;

int iRange= 0;
int iN=0;

int fact(int n)
{
if ( n<1)
return 1;
else
return fact(n-1)*n;
}

void print_combinations(int n, int iMxM)
{
int iBigSetFact=fact(iMxM);
int iDiffFact=fact(iMxM-n);
int iSmallSetFact=fact(n);
int iNoTotComb = (iBigSetFact/(iDiffFact*iSmallSetFact));
cout<<"The number of possible combinations is: "<<iNoTotComb<<endl;
cout<<" and these combinations are the following: "<<endl;

int i, j, k;
for (i = 0; i < iMxM - 1; i++)
{
for (j = i + 1; j < iMxM ; j++)
{
//for (k = j + 1; k < iMxM; k++)
cout<<i+1<<j+1<<endl;
}
}
}

int main()
{
cout<<"Please give the range (max) within which the combinations are to be found: "<<endl;
cin>>iRange;
cout<<"Please give the desired number of combinations: "<<endl;
cin>>iN;
print_combinations(iN,iRange);
return 0;
}``````

The problem:
The part of code concerning the printing of the combinations works only for n=2, iRange =4 and i need help to generize it(have to change lines 25 -33).

thanks

I solved it myself. ... Anyway thanks for nothing..... :D :D