void ft_putchar(char c) { write (1, &c, 1); } void ft_print_screen(int *t, int size) { int i; i = 1; while (i < size) { if (t[i - 1] >= t[i]) i++; } { i = 0; while (i < size) ft_putchar(t[i++] + '0'); if (t[0] < (10 - size)) { ft_putchar(','); ft_putchar(' '); } } } void ft_print_combn(int n) { int i; int tab[n]; i = 0; if (n == 1) while (i < 10) ft_putchar(i++ + '0'); while (i < n) tab[i++] = 0; while (tab[0] <= (10 - n) && n > 1) { ft_print_screen(tab, n); tab[n - 1]++; i = n; while (i && n > 1) { i--; if (tab[i] > 9) { tab[i - 1]++; tab[i] = 0; } } } } int main() { ft_print_combn(8); return (0); }
Standard input is empty
01234567, 01234568, 01234569, 01234578, 01234579, 01234589, 01234678, 01234679, 01234689, 01234789, 01235678, 01235679, 01235689, 01235789, 01236789, 01245678, 01245679, 01245689, 01245789, 01246789, 01256789, 01345678, 01345679, 01345689, 01345789, 01346789, 01356789, 01456789, 02345678, 02345679, 02345689, 02345789, 02346789, 02356789, 02456789, 03456789, 12345678, 12345679, 12345689, 12345789, 12346789, 12356789, 12456789, 13456789, 23456789