You are on page 1of 4

// Liet ke tat ca cac hoan vi X={0,1,2...

n}
#include "stdio.h"
#define MAX 10
int S[MAX],A[MAX],n,dem=0;
void thu(int i),print();
void main()
{
int j;
printf("n= ");scanf("%d",&n);
for(j=0;j<=n;j++) A[j]=1;
thu(0);
}
void print()
{
printf("\n%5d:",++dem);
for (int i=0;i<=n;i++) printf("%d",S[i]);
}
void thu(int i)
{
int j;
for(j=0;j<=n;j++)
if(A[j])
{
S[i]=j;A[j]=0;
if(i==n)print(); else thu(i+1);
A[j]=1;
}
}

// Liet ke tat ca cac hoan vi X={0,1,2...n-1}


#include "stdio.h"
#define MAX 10
int S[MAX],A[MAX],n,dem=0;
void thu(int i),print();
void main()
{
int j;
printf("n= ");scanf("%d",&n);
for(j=0;j<n;j++) A[j]=1;
thu(0);
}
void print()
{
printf("\n%5d:",++dem);
for (int i=0;i<n;i++) printf("%d",S[i]);
}
void thu(int i)
{
int j;
for(j=0;j<n;j++)
if(A[j])
{
S[i]=j;A[j]=0;
if(i==n-1)print(); else thu(i+1);
A[j]=1;
}
}

// Liet ke tat ca tap con gom k phan tu cua X={0,1,2...n}


#include "stdio.h"
#define MAX 10
int S[MAX],A[MAX],n,k,dem=0;
void thu(int i),print();
void main()
{
printf("Nhap n: ");scanf("%d",&n);
printf("Nhap k: ");scanf("%d",&k);
thu(1);
}
void print()
{
printf("\n%3d:",++dem);
for (int i=1;i<=k;i++) printf("%d",S[i]);
}
void thu(int i)
{
int j;
for(j=S[i-1]+1;j<=n;j++)
{
S[i]=j;
if(i==k)
print();
else thu(i+1);
}
}

// Liet ke tat ca tap con cua X={0,1,2...n}


#include "stdafx.h"
#define MAX 10
int S[MAX],n,dem=0;
void thu(int i),print();
void main()
{
printf("Nhap n: ");scanf("%d",&n);
thu(1);
}
void print()
{
int i;
printf("\n{");
for(i=1;i<=n;i++)
if(S[i])printf("%d,",i);
printf("}");
}
void thu(int i)
{
int j;
for(j=0;j<=1;j++)
{
S[i]=j;
if(i==n)print();else thu(i+1);
}
}