1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#define ARRAY_LENGTH 5
#define ARRAY_DATA_TYPE unsigned char
#define INCREMENT_LIMIT 3
void print_array(ARRAY_DATA_TYPE *array, size_t len)
{
for(size_t cell = 0; cell < len; cell++)
{
printf("%d ", array[cell]);
}
putchar('\n');
}
int main(void)
{
ARRAY_DATA_TYPE array[ARRAY_LENGTH] = {0};
// Initial state
print_array(array, ARRAY_LENGTH);
// Increment
for(size_t cell = 1; cell < ARRAY_LENGTH; cell++)
{
while(array[cell] != INCREMENT_LIMIT)
{
for(unsigned int inc = 1; inc <= INCREMENT_LIMIT; inc++)
{
array[0] = inc;
print_array(array, ARRAY_LENGTH);
}
array[0] = 0;
array[cell] += 1;
print_array(array, ARRAY_LENGTH);
}
}
puts("DONE");
return 0;
} |
Partager