aboutsummaryrefslogtreecommitdiff
path: root/c00/ex08/ft_print_combn.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-07-28 13:47:11 +0200
committerCharles <sircharlesaze@gmail.com>2019-07-28 13:47:11 +0200
commite534578eecebd27c4e7e235ce85961446e6c2e43 (patch)
treee581555b571035e6633134e1ed9c6280531a18a3 /c00/ex08/ft_print_combn.c
parent8172a7f70e35942cf102fb07963687d9ddace818 (diff)
downloadpiscine-e534578eecebd27c4e7e235ce85961446e6c2e43.tar.gz
piscine-e534578eecebd27c4e7e235ce85961446e6c2e43.tar.bz2
piscine-e534578eecebd27c4e7e235ce85961446e6c2e43.zip
test commit for reload branch
Diffstat (limited to 'c00/ex08/ft_print_combn.c')
-rw-r--r--c00/ex08/ft_print_combn.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/c00/ex08/ft_print_combn.c b/c00/ex08/ft_print_combn.c
index 975c306..c7b415f 100644
--- a/c00/ex08/ft_print_combn.c
+++ b/c00/ex08/ft_print_combn.c
@@ -10,16 +10,34 @@
/* */
/* ************************************************************************** */
-/*#include <unistd.h>*/
+#include <unistd.h>
-/*void ft_print_combn(int n)*/
-/*{*/
- /*int i;*/
+void ft_putchar(char c)
+{
+ write(STDOUT_FILENO, &c, 1);
+}
- /*if (n == 0)*/
- /*return ;*/
- /*i = 0;*/
- /*while (i < 10)*/
- /*{*/
- /*}*/
-/*}*/
+void comb(int start, int n)
+{
+ int i;
+
+ if (n == 0)
+ {
+ ft_putchar(',');
+ ft_putchar(' ');
+ return ;
+ }
+ i = start + 1;
+ while (i < 10)
+ {
+ ft_putchar(start + '0');
+ ft_putchar(i + '0');
+ comb(i, n - 1);
+ i++;
+ }
+}
+
+void ft_print_combn(int n)
+{
+ comb(0, n);
+}