#include<bits/stdc++.h>
using namespace std;
int number[101], n, r;
void combination(int pos, int last)
{
if(pos == r+1)
{
for(int i=1; i<=r; i++)
cout << number[i] << " ";
cout << "\n";
return;
}
for(int i=last+1; i<=n-r+pos; i++)
{
number[pos] = i;
combination(pos+1, i);
}
}
int main()
{
cout << "Enter n and r :: ";
cin >> n >> r;
cout << "Combinations are :: \n";
combination(1, 0);
return 0;
}
Comments
Post a Comment