#include"stdio.h"
#include"stdlib.h"
#include"string.h"
int count=0;
int a[20];
int n=5, r=3;
void output()
{
int j;
for(j=1; j<=r; j++)
printf("%d ", a[j]);
count++;
printf("\n");
}
void comb(int ri)
{
if(ri>r)
output();
else
{
while(ri+a[ri]-1>=r+1)
{
a[ri]=a[ri]-1;
a[ri+1]=a[ri];
comb(ri+1);
}
ri=ri-1;
}
}
int main()
{
a[1]=n+1;
if (r>n)
printf("Input n, r error!\n");
else
{
comb(1);
printf("The total combinations are %d.\n",count);
}
}