42_C_PISCINE/C/c00/ex06/ft_print_comb2.c
Camille Chauvet 29ed24d567 init
2023-05-17 16:45:25 +00:00

82 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_comb2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 13:08:46 by cchauvet #+# #+# */
/* Updated: 2022/07/14 14:25:34 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <stdbool.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
bool ft_sames(char a, char b, char c, char d)
{
char e;
b = a;
if (e != b)
return (false);
e = b;
if (e != c)
return (false);
e = c;
if (e != d)
return (false);
return (true);
}
void ft_result(char a, char b, char c, char d)
{
if (!ft_sames(a, b, c, d))
{
ft_putchar(a);
ft_putchar(b);
ft_putchar(' ');
ft_putchar(c);
ft_putchar(d);
if (!((a == '9') && (b == '8') && (c == '9') && (d == '9')))
{
ft_putchar(',');
ft_putchar(' ');
}
}
}
void ft_print_comb2(void)
{
char a;
char b;
char c;
char d;
a = '0';
while (a <= '9')
{
b = '0';
while (b <= '8')
{
c = '0';
while (c <= '9')
{
d = '0';
while (d <= '9')
{
ft_result(a, b, c, d++);
}
c++;
}
b++;
}
a++;
}
}