Created
February 5, 2014 10:49
-
-
Save calindotgabriel/8821066 to your computer and use it in GitHub Desktop.
binary counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#define Nmax 40 | |
int n, mask[40]; | |
int next(int mask[]) { | |
int i ; | |
for (i = 0 ; i < n && mask[i]; i ++) | |
mask[i] = 0; | |
if (i < n) { | |
mask[i] = 1; | |
return 1; | |
} | |
return 0; | |
} | |
void print(int mask[]) { | |
for (int i = 0 ; i < n ; i ++) | |
printf("%d ", mask[i]); | |
printf("\n"); | |
} | |
int main() | |
{ | |
freopen("energii.in", "r", stdin); | |
// freopen("energii.out", "w", stdout); | |
scanf("%d", &n); | |
while (next(mask)) { | |
print(mask); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment