fork(2) download
  1. void ft_putchar(char c)
  2. {
  3. write (1, &c, 1);
  4. }
  5.  
  6.  
  7. void ft_print_screen(int *t, int size)
  8.  
  9. {
  10.  
  11. int i;
  12.  
  13. int islower;
  14.  
  15.  
  16.  
  17. i = 1;
  18.  
  19. islower = 1;
  20.  
  21. while (i < size)
  22.  
  23. {
  24.  
  25. if (t[i - 1] >= t[i])
  26.  
  27. islower = 0;
  28.  
  29. i++;
  30.  
  31. }
  32.  
  33. if (islower)
  34.  
  35. {
  36.  
  37. i = 0;
  38.  
  39. while (i < size)
  40.  
  41. ft_putchar(t[i++] + '0');
  42.  
  43. if (t[0] < (10 - size))
  44.  
  45. {
  46.  
  47. ft_putchar(',');
  48.  
  49. ft_putchar(' ');
  50.  
  51. }
  52.  
  53. }
  54.  
  55. }
  56.  
  57.  
  58.  
  59. void ft_print_combn(int n)
  60.  
  61. {
  62.  
  63. int i;
  64.  
  65. int tab[n];
  66.  
  67.  
  68.  
  69. i = 0;
  70.  
  71. if (n == 1)
  72.  
  73. while (i < 10)
  74.  
  75. ft_putchar(i++ + '0');
  76.  
  77. while (i < n)
  78.  
  79. tab[i++] = 0;
  80.  
  81. while (tab[0] <= (10 - n) && n > 1)
  82.  
  83. {
  84.  
  85. ft_print_screen(tab, n);
  86.  
  87. tab[n - 1]++;
  88.  
  89. i = n;
  90.  
  91. while (i && n > 1)
  92.  
  93. {
  94.  
  95. i--;
  96.  
  97. if (tab[i] > 9)
  98.  
  99. {
  100.  
  101. tab[i - 1]++;
  102.  
  103. tab[i] = 0;
  104.  
  105. }
  106.  
  107. }
  108.  
  109. }
  110.  
  111. }
  112.  
  113. int main()
  114. {
  115. ft_print_combn(8);
  116. return (0);
  117. }
Success #stdin #stdout 1.04s 2108KB
stdin
Standard input is empty
stdout
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