Browse Source

correct

master
Elouan MARTINET 4 years ago
parent
commit
0a6e61d83e
  1. 4
      ex00/ft_iterative_factorial.c
  2. 4
      ex01/ft_recursive_factorial.c
  3. 2
      ex02/ft_iterative_power.c
  4. 4
      ex03/ft_recursive_power.c
  5. 2
      ex04/ft_fibonacci.c
  6. 4
      ex05/ft_sqrt.c
  7. 8
      ex06/ft_is_prime.c
  8. 8
      ex07/ft_find_next_prime.c
  9. 35
      ex08/ft_eight_queens_puzzle.c

4
ex00/ft_iterative_factorial.c

@ -6,7 +6,7 @@
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/03 01:00:38 by emartine #+# #+# */
/* Updated: 2017/08/03 01:40:02 by emartine ### ########.fr */
/* Updated: 2017/08/06 21:39:03 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,8 @@ int ft_iterative_factorial(int nb)
{
int r;
if (nb < 0 || nb > 12)
return (0);
if (nb <= 1)
return (1);
r = 1;

4
ex01/ft_recursive_factorial.c

@ -6,12 +6,14 @@
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/03 01:28:14 by emartine #+# #+# */
/* Updated: 2017/08/03 01:30:55 by emartine ### ########.fr */
/* Updated: 2017/08/06 21:50:47 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_factorial(int nb)
{
if (nb < 0 || nb > 12)
return (0);
if (nb <= 1)
return (1);
return (nb * ft_recursive_factorial(nb - 1));

2
ex02/ft_iterative_power.c

@ -6,7 +6,7 @@
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/03 01:31:58 by emartine #+# #+# */
/* Updated: 2017/08/03 01:39:35 by emartine ### ########.fr */
/* Updated: 2017/08/06 21:56:02 by emartine ### ########.fr */
/* */
/* ************************************************************************** */

4
ex03/ft_recursive_power.c

@ -6,7 +6,7 @@
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/03 01:40:39 by emartine #+# #+# */
/* Updated: 2017/08/03 01:47:39 by emartine ### ########.fr */
/* Updated: 2017/08/06 22:01:30 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,8 @@ int ft_recursive_power(int nb, int power)
if (power < 0)
return (0);
if (power == 0)
return (1);
if (power == 1)
return (nb);
r = ft_recursive_power(nb, power / 2);

2
ex04/ft_fibonacci.c

@ -6,7 +6,7 @@
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/03 01:51:51 by emartine #+# #+# */
/* Updated: 2017/08/03 01:58:35 by emartine ### ########.fr */
/* Updated: 2017/08/06 22:09:18 by emartine ### ########.fr */
/* */
/* ************************************************************************** */

4
ex05/ft_sqrt.c

@ -6,7 +6,7 @@
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/03 02:00:13 by emartine #+# #+# */
/* Updated: 2017/08/03 06:12:11 by emartine ### ########.fr */
/* Updated: 2017/08/06 22:12:08 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,7 @@ int ft_sqrt(int nb)
if (nb == 1)
return (1);
r = 2;
while (r * r < nb)
while (r * r <= nb)
{
if (r * r == nb)
return (r);

8
ex06/ft_is_prime.c

@ -6,7 +6,7 @@
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/03 05:47:58 by emartine #+# #+# */
/* Updated: 2017/08/03 06:10:37 by emartine ### ########.fr */
/* Updated: 2017/08/06 22:27:27 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,8 +33,12 @@ int ft_is_prime(int nb)
int up;
int i;
if (nb <= 1)
return (0);
if (nb <= 3)
return (1);
up = down_sqrt(nb);
if (up < 1)
if (up <= 1)
return (0);
i = 2;
while (i <= up)

8
ex07/ft_find_next_prime.c

@ -6,7 +6,7 @@
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/03 12:07:48 by emartine #+# #+# */
/* Updated: 2017/08/03 14:52:13 by emartine ### ########.fr */
/* Updated: 2017/08/06 22:28:05 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,6 +33,10 @@ int ft_is_prime(int nb)
int up;
int i;
if (nb <= 1)
return (0);
if (nb <= 3)
return (1);
up = down_sqrt(nb);
if (up < 1)
return (0);
@ -50,7 +54,7 @@ int ft_find_next_prime(int nb)
{
int i;
i = nb + 1;
i = nb;
while (1)
{
if (ft_is_prime(i))

35
ex08/ft_eight_queens_puzzle.c

@ -5,42 +5,23 @@
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/04 11:24:25 by emartine #+# #+# */
/* Updated: 2017/08/04 12:30:36 by emartine ### ########.fr */
/* Created: 2017/08/05 23:39:34 by emartine #+# #+# */
/* Updated: 2017/08/05 23:46:28 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
int calc_queen(int x, int y)
int available(int p[8])
{
return (1);
;
}
int calc_row(int x)
int recur()
{
int y;
int r;
y = 1;
r = 0;
while (y <= 8)
{
r += calc_queen(x, y);
y++;
}
return (r);
;
}
// 92
int ft_eight_queens_puzzle(void)
{
int x;
int r;
x = 1;
r = 0;
while (x <= 8)
{
r += calc_row(x);
x++;
}
return (r);
int p[8];
}

Loading…
Cancel
Save