Tricky for finding Combination of numbers by given r length

 #include<stdio.h>

void combo2(int [],int [],int ,int,int,int);

int main()

{

int k;

scanf("%d",&k);

int a[k];

int l=0;

 for(l=0;l<k;l++)

 {

  scanf("%d",&a[l]);

 }

int m;

scanf("%d",&m);

int data[m];

combo2(a,data,0,k-1,0,m);

return 0;

}

void combo2(int a[],int data[],int start,int end,int index,int r)

{

if(index==r)

{ int i;

for(i=0;i<r;i++)

{

printf("%d ",data[i]);

}

printf("\n");

}

else

{int k;

for(k=start;k<=end&& end-k+1>=r-index;k++)

{

data[index]=a[k];

combo2(a,data,k+1,end,index+1,r);

}

}

}


No comments:

Post a Comment

LFX Mentorship Applications are now open

Introduction: The LFX Mentorship Program turned out to be a transformative expedition in my professional voyage. The initiative provided an ...