
Patrick B. answered 02/03/21
Math and computer tutor/teacher
It lists subsets of the set {1,2,3,4,5,....,N}
Dorsa R.
asked 02/03/21void bin(int x, int value)
{
if(x == 0)
return;
bin(x / 2, value - 1);
if(x % 2)
printf("%d ", value);
}
int Pow(int a, int b)
{
int d = 1;
for(int i = 1; i <= b; i++)
d *= a;
return d;
}
int main()
{
int n;
scanf("%d", &n);
for(int i = Pow(2, n) - 1; i >= 0; i--)
{
printf("{ ");
bin(i, n);
printf("}\n");
}
}
Patrick B. answered 02/03/21
Math and computer tutor/teacher
It lists subsets of the set {1,2,3,4,5,....,N}
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.