cout<<"PLEASE ENTER SINGLE CHARCTERS";//char array .press return after each entry
for(int i=0;i<n;i++)//inputting
cin>>str[i];
system("cls");
//----------------------------------------------------------------------------
for(i=0;i<n;i++)//n輸入几個就几個
bin[i]=0;
i=0;
cout<<"POWERSET IS"<<endl;//powerset is set containing subsets of given set
cout<<"{";
while(i<exp(n*log(2)))//no: of subset is 2^n where n is the no:of elements
{
cout<<endl;
j=0;
cout<<"{";
for(int k=0;k<n;k++)
{
if(bin[k]==1)
cout<<str[k];//outputs if bin[k]=1
}
cout<<"}";
j=0;
bin[j]=bin[j]+1;
while(bin[j]>1) //generating binary sequence,000,001,010,011.....
{
bin[j]=bin[j]-2;
j=j+1;
bin[j]=bin[j]+1;
}
i=i+1;
}
cout<<"}"<<endl;
}
以上是我在網路上找到的答案..
--
有問題可以寫信給我physic...@bbs.dyu.edu.tw
--
[1;32m※ Origin: [33m大葉大學戀戀紅城 [37m<bbs.dyu.edu.tw> [m
[1;32m※ From : [36msw59-244-244.adsl.seed.net.tw [m