En Subject C05
En Subject C05
En Subject C05
C 05
Summary: this document is the subject for the C 05 module of the C Piscine @ 42.
Contents
I Instructions 2
II Foreword 4
IV Exercise 01 : ft_recursive_factorial 7
V Exercise 02 : ft_iterative_power 8
VI Exercise 03 : ft_recursive_power 9
IX Exercise 06 : ft_is_prime 12
X Exercise 07 : ft_find_next_prime 13
1
Chapter I
Instructions
• Make sure you have the appropriate permissions on your files and directories.
• You have to follow the submission procedures for all your exercises.
• On top of that, your exercises will be checked and graded by a program called
Moulinette.
• Moulinette is very meticulous and strict in its evaluation of your work. It is entirely
automated and there is no way to negotiate with it. So if you want to avoid bad
surprises, be as thorough as possible.
• Moulinette is not very open-minded. It won’t try and understand your code if it
doesn’t respect the Norm. Moulinette relies on a program called norminette to
check if your files respect the norm. TL;DR: it would be idiotic to submit a piece
of work that doesn’t pass norminette’s check.
• These exercises are carefully laid out by order of difficulty - from easiest to hardest.
We will not take into account a successfully completed harder exercise if an easier
one is not perfectly functional.
• Using a forbidden function is considered cheating. Cheaters get -42, and this grade
is non-negotiable.
• Moulinette compiles with these flags: -Wall -Wextra -Werror, and uses gcc.
• You cannot leave any additional file in your directory than those specified in the
subject.
• Got a question? Ask your peer on the right. Otherwise, try your peer on the left.
2
C Piscine C 05
• Check out the "C Piscine" part of the forum on the intranet, or the slack Piscine.
• Examine the examples thoroughly. They could very well call for details that are
not explicitly mentioned in the subject...
3
Chapter II
Foreword
Here are some lyrics extract from the Harry Potter saga:
Or perhaps in Slytherin
You’ll make your real friends,
Those cunning folks use any means
4
C Piscine C 05
Unfortunately, this subject’s got nothing to do with the Harry Potter saga, which is
too bad, because your exercises won’t be done by magic.
5
Chapter III
Exercise 00 : ft_iterative_factorial
Exercise 00
ft_iterative_factorial
Turn-in directory : ex00/
Files to turn in : ft_iterative_factorial.c
Allowed functions : None
• Create an iterated function that returns a number. This number is the result of a
factorial operation based on the number given as a parameter.
6
Chapter IV
Exercise 01 : ft_recursive_factorial
Exercise 01
ft_recursive_factorial
Turn-in directory : ex01/
Files to turn in : ft_recursive_factorial.c
Allowed functions : None
• Create a recursive function that returns the factorial of the number given as a
parameter.
7
Chapter V
Exercise 02 : ft_iterative_power
Exercise 02
ft_iterative_power
Turn-in directory : ex02/
Files to turn in : ft_iterative_power.c
Allowed functions : None
• Create an iterated function that returns the value of a power applied to a number.
An power lower than 0 returns 0. Overflows must not be handled.
8
Chapter VI
Exercise 03 : ft_recursive_power
Exercise 03
ft_recursive_power
Turn-in directory : ex03/
Files to turn in : ft_recursive_power.c
Allowed functions : None
• Create a recursive function that returns the value of a power applied to a number.
9
Chapter VII
Exercise 04 : ft_fibonacci
Exercise 04
ft_fibonacci
Turn-in directory : ex04/
Files to turn in : ft_fibonacci.c
Allowed functions : None
• Create a function ft_fibonacci that returns the n-th element of the Fibonacci
sequence, the first element being at the 0 index. We’ll consider that the Fibonacci
sequence starts like this: 0, 1, 1, 2.
10
Chapter VIII
Exercise 05 : ft_sqrt
Exercise 05
ft_sqrt
Turn-in directory : ex05/
Files to turn in : ft_sqrt.c
Allowed functions : None
• Create a function that returns the square root of a number (if it exists), or 0 if the
square root is an irrational number.
11
Chapter IX
Exercise 06 : ft_is_prime
Exercise 06
ft_is_prime
Turn-in directory : ex06/
Files to turn in : ft_is_prime.c
Allowed functions : None
12
Chapter X
Exercise 07 : ft_find_next_prime
Exercise 07
ft_find_next_prime
Turn-in directory : ex07/
Files to turn in : ft_find_next_prime.c
Allowed functions : None
• Create a function that returns the next prime number greater or equal to the number
given as argument.
13
Chapter XI
Exercise 08
• Create a function that displays all possible placements of the ten queens on a
chessboard which would contain ten columns and ten lines, without them being
able to reach each other in a single move, and returns the number of possibilities.
int ft_ten_queens_puzzle(void);
• The sequence goes from left to right. The first digit represents the first Queen’s
position in the first column (the index starting from 0). The Nth digit represents
the Nth Queen’s position in the Nth column.
14