Skip to content

Instantly share code, notes, and snippets.

@calindotgabriel
Created February 5, 2014 10:49
Show Gist options
  • Save calindotgabriel/8821066 to your computer and use it in GitHub Desktop.
Save calindotgabriel/8821066 to your computer and use it in GitHub Desktop.
binary counter
#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