Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdio.h>
- void ptc(char c)
- {
- write(1, &c, 1);
- }
- void inter(void)
- {
- ptc(',');
- ptc(' ');
- }
- void ft_putnbr(int nb)
- {
- if (nb < 0)
- {
- nb = -nb;
- }
- if (nb >= 10)
- {
- ft_putnbr(nb / 10);
- ft_putnbr(nb % 10);
- }
- else
- ptc(nb + '0');
- }
- int is_finish(int n, int *tab)
- {
- if (tab[0] == 10-n)
- {
- return -1;
- }
- else
- return 1;
- }
- void ft_print_combn(int n)
- {
- int tab[10] = {0};
- int i;
- int pos;
- int len;
- int copy;
- int l;
- int m;
- int nombre = 0;
- m = 0;
- len = 0;
- pos = 1;
- i = 0;
- n--;
- copy = n;
- //printf("i : %d - n : %d\n", i, n);
- while (i <= n)
- {
- tab[i] = i;
- i++;
- }
- int j = 0;
- while (j <= n)
- j++;
- while (len <= copy)
- {
- ft_putnbr(tab[len]);
- len++;
- }
- inter();
- while (is_finish(n, tab) != -1)
- {
- l = 1;
- m = 0;
- pos = 1;
- len = 0;
- if (tab[n] != 9)
- tab[n] = tab[n] + 1;
- else if (tab[n] == 9)
- {
- while (tab[n - pos] + 1 == tab[n - m])
- {
- pos++;
- m++;
- }
- tab[ n - pos] += 1;
- j = n - pos + 1;
- l = 1;
- while (j <= n)
- {
- tab[j] = tab[ n - pos] + l;
- j++;
- l++;
- }
- }
- while (len <= copy)
- {
- ft_putnbr(tab[len]);
- len++;
- }
- nombre++;
- inter();
- }
- // printf("|%d|\n", nombre);
- }
- int main(void)
- {
- ft_print_combn(5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement