열렬히.뛰기

c01

école 42 > C > c01

ex00

c
void	ft_ft(int *abr)
{
	*abr = 42;
}

ex01

c
void	ft_ultimate_ft(int *********nbr)
{
	*********nbr = 42;
}

ex02

c
void	ft_swap(int *a, int *b)
{
	int	temp;

	temp = *a;
	*a = *b;
	*b = temp;
}

ex03

c
void	ft_div_mod(int a, int b, int *div, int *mod)
{
	*div = a / b;
	*mod = a % b;
}

ex04

c
#include <unistd.h>

void	ft_ultimate_div_mod(int *a, int *b)
{
	int	temp;
	int	temp2;

	temp = *a / *b;
	temp2 = *a % *b;
	*a = temp;
	*b = temp2;
}

ex05

c
#include <unistd.h>

void	ft_putstr(char *str)
{
	int	n;

	n = 0;
	while (str[n] != '\0')
		write(1, &str[n++], 1);
}

ex06

c
int	ft_strlen(char *str)
{
	int	x;

	x = 0;
	while(str[x] != '\0')
		x++;
	return (x);
}

ex07

c
void	ft_rev_int_tab(int *tab, int size)
{
	int	temp;
	int i;

	i = 0;
	while (i < size)
	{
		temp = tab[i];
		tab[size - i - 1] = temp;
		tab[i] = tab[size - i - 1];
		i++;
	}
}

ex08

c
void	ft_sort_int_tab(int *tab, int size)
{
	int	i;
	int	j;
	int	temp;

	i = size;
	while (--i > 0)
	{
		j = -1;
		while (++j < i)
			{
				temp = tab[j];
				tab[j + 1] = temp;
				tab[j] = tab[j + 1];
			}
		}
	}
}