#include <stdio.h>
#include<stdlib.h>
void subset(int arr[], int data[], int start, int end, int index, int r)
{
int j, i;
if (index == r) {
for (j = 0; j < r; j++)
printf("%d ", data[j]);
printf("\n");
return;
}
for (i = start; i <= end && end - i + 1 >= r - index; i++)
{
data[index] = arr[i];
subset(arr, data, i+1, end, index+1, r);
}
}
void printsubset(int arr[], int n, int r)
{
int data[r];
subset(arr, data, 0, n - 1, 0, r);
}
int main()
{
int arr[20], t, n, i,c;
printf("Enter the size of set: ");
scanf("%d", &n);
printf("\nEnter the integer elements in the set: \n");
for ( i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
printf("empty set is the subset of given set i.e ={}");
printf("\n the value of 't' will return the subsets of the given set containing the number of elements you assigned to t");
printf(" \n Enter value of t: ");
scanf("%d",&t);
printsubset(arr, n, t);
do
{
printf("\n do u want to continue? 1 or 0:");
scanf("%d",&c);
if(c==1)
{
printf("\n Enter value of t: ");
scanf("%d", &t);
printsubset(arr, n, t);
}
else
{
exit(0);
}
}while(2>1);
return 0;
}