Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Selection of the number n k is the number of different conditions set
#include<stdio.h>
void f(int N,int k,int a[],int b[],int m);
int main()
{
int N=5;
int k=3;
int a[10];
int b[5]={1,2,3,4,5};
f(N,k,a,b,0);
return 0;
}
void f(int N,int k,int a[],int b[],int m)
{
int i;
if(k==0)
{
for(i=0;i<m;i++)
{
printf("%d",a[i]);
}
printf(" ");
}
else
{
for(i=N;i>=k;i--)
{
a[m]=b[i-1];
f(i-1,k-1,a,b,m+1);
}
}
}