您的位置:首页 > 其它

实现生成子集

2012-12-03 16:38 211 查看
//============================================================================
// Name        : 1111.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<cmath>
using namespace std;

void to_binary(unsigned long n)
{
int r;
r=n%2;
if(n>=2)
to_binary(n/2);
cout<<r;//putchar(r?'1':'0')
return;
}
void PaiLie(int n)
{
for(int i=1;i<(1<<n);i++)
{
cout<<i<<endl;
to_binary(i);
cout<<endl;
}
}
int main() {
cout<<"Enter The Num!"<<endl;
int i;
cin>>i;
PaiLie(i);
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: