Exercise Algorithm 2 (selection number n of the number of different conditions set k)

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.
This link: https://blog.csdn.net/qq_36058813/article/details/102768575

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);
		}
	}
}

 

Guess you like

Origin blog.csdn.net/qq_36058813/article/details/102768575