Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- using namespace std;
- void print(int arr[], int n){
- for(int i = 1; i <= n; i++)
- {
- cout<<arr[i];
- }
- cout<<endl;
- }
- void next(int arr[], int n){
- int position = n;
- while(position >= 1 && arr[position] == 1) position--;
- arr[position] = 1;
- for(int i = position+1; i < n; i++){
- arr[position] = 0;
- }
- }
- main()
- {
- int n, arr[100005]={0};
- cin>>n;
- int length=pow(2,n);
- for(int i = 1; i < length; i++)
- {
- print(arr, n);
- next(arr, n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement