Compare commits

...

3 Commits

Author SHA1 Message Date
tosu e3032cac96 Add ft_print_comb2 2023-03-17 02:17:27 +01:00
tosu ba2b0c541e Refactor ft_print_comb.c 2023-03-17 02:16:53 +01:00
tosu 04b4291970 Add ft_putnbr.c 2023-03-17 02:15:59 +01:00
3 changed files with 145 additions and 26 deletions

View File

@ -12,34 +12,39 @@
#include <unistd.h>
void ft_print_comb(void)
void print_abc(char a, char b, char c)
{
int a;
int b;
int c;
write(1, &a, 1);
write(1, &b, 1);
write(1, &c, 1);
if (a != '7')
{
write(1, ", ", 2);
}
}
a = '0';
while (a <= '7')
{
b = a + 1;
while (b <= '8')
{
c = b + 1;
while (c <= '9')
{
write(1, &a, 1);
write(1, &b, 1);
write(1, &c, 1);
if (a != '7')
{
write(1, ", ", 2);
}
c++;
}
b++;
}
a++;
}
void ft_print_comb(void)
{
int a;
int b;
int c;
a = '0';
while (a <= '7')
{
b = a + 1;
while (b <= '8')
{
c = b + 1;
while (c <= '9')
{
print_abc(a, b, c);
c++;
}
b++;
}
a++;
}
}
/* ////

64
ex06/ft_print_comb2.c Normal file
View File

@ -0,0 +1,64 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_reverse_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/15 21:50:37 by tischmid #+# #+# */
/* Updated: 2023/03/16 05:00:01 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
char digit_to_char(char c)
{
return (c + '0');
}
void print_a_and_b(int a, int b)
{
char a_tenth;
char b_tenth;
a_tenth = digit_to_char(a / 10);
a = digit_to_char(a % 10);
b_tenth = digit_to_char(b / 10);
b = digit_to_char(b % 10);
write(1, &a_tenth, 1);
write(1, &a, 1);
write(1, " ", 1);
write(1, &b_tenth, 1);
write(1, &b, 1);
if (a != 98)
{
write(1, ", ", 2);
}
}
void ft_print_comb2(void)
{
int a;
int b;
a = 0;
while (a <= 98)
{
b = a + 1;
while (b <= 99)
{
print_a_and_b(a, b);
b++;
}
a++;
}
}
/* ////
int main(void)
{
ft_print_comb2();
return (0);
}
*/ ////

50
ex07/ft_putnbr.c Normal file
View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_reverse_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/15 21:50:37 by tischmid #+# #+# */
/* Updated: 2023/03/16 05:00:01 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putnbr(int nb)
{
char last_digit;
if (nb < 0)
{
write(1, "-", 1);
if (nb == 1 << 31)
{
nb += 2e9;
write(1, "2", 1);
}
nb *= -1;
}
last_digit = nb % 10 + 0x30;
if (nb > 9)
{
nb /= 10;
ft_putnbr(nb);
}
write(1, &last_digit, 1);
}
/* ////
int main(void)
{
ft_putnbr(-2147483648);
// ft_putnbr(-10000);
// ft_putnbr(-1);
// ft_putnbr(0);
// ft_putnbr(1);
// ft_putnbr(10000);
// ft_putnbr(2147483647);
return (0);
}
*/ ////