aboutsummaryrefslogtreecommitdiff
path: root/c00/ex06/ft_print_comb2.c
blob: 7e6d2d127d8a116cfe7498cf56026225f66e6d7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_print_comb2.c                                   :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <charles.cabergs@gmail.com>       +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2019/07/03 08:32:30 by cacharle          #+#    #+#             */
/*   Updated: 2019/07/03 14:28:09 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <unistd.h>

void	my_putchar(char c)
{
	write(1, &c, 1);
}

void	print_nb(int nb)
{
	my_putchar((char)(nb / 10 + '0'));
	my_putchar((char)(nb % 10 + '0'));
}

void	ft_print_comb2(void)
{
	int	nb1;
	int	nb2;

	nb1 = 0;
	while (nb1 < 100)
	{
		nb2 = nb1 + 1;
		while (nb2 < 100)
		{
			print_nb(nb1);
			my_putchar(' ');
			print_nb(nb2);
			if (!(nb1 == 98 && nb2 == 99))
			{
				my_putchar(',');
				my_putchar(' ');
			}
			nb2++;
		}
		nb1++;
	}
}