M

#### mary8shtr

{}

{1}

{2}

{1,2}

or for n=3 we have:

{}

{1}

{2}

{3}

{1,2}

{1,3}

{2,3}

{1,2,3}

meantime this program should be solved with tow way.

recursive function and Non-recursive.Can also be used in solving the problem of bitwise operations.

my algorithm that is for per subset exists one number. these numbers are form 0 until (2^n)-1.allow me explain it with a example.

n=3

{ } 000 0

{1} 100 4

{2} 010 2

{3} 001 1

{1,2} 110 6

{1,3} 101 5

{2,3} 011 3

{1,2,3} 111 7

The third column show some number(fn) that i use in code.now we know per number of subset has to state(sn).0 or 1. this means it exists or not exists.now i should match fn and sn.and suggested way is use of bitwise operators.(operator &).and now i don't know what do and thing with else thing.

#include <iostream>

using namespace std;

#include <conio.h>

#include <string.h>

int pow(int a,int b)

{

int p=1;

for(int i=0;i<b;i++)

p=p*a;

return p;

}

struct ar

{

int binary;

int content;

};

int main()

{

int testcase=0;

int n;

ar *a;

a=new ar [2000];

cin>>testcase;

int i=0;

while(i<testcase)

{

cin>>n;

for(int j=0,k=1;j<n;j++,k++)

{

a[j].content=k;

a[j].binary=2;

}

for(int p=0;p<pow(2,n)-1;p++)

{

cout<<'{';

for(int m=0;m<n;m++)

{

int b;

b=a[m].binary&p;

if(b==1)

cout<<a

*.content<<' ';*

}

cout<<'}';

}

cout<<endl;

i++;

}

return 0;

}

}

cout<<'}';

}

cout<<endl;

i++;

}

return 0;

}