From c49b969659d8761442a560f8feda436bfb7b01e8 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 27 Mar 2025 17:24:15 +0100 Subject: Ajout des cours du 10 au 27 mars --- "semestre 2/informatique/6- R\303\251cursion.md" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'semestre 2/informatique/6- Récursion.md') diff --git "a/semestre 2/informatique/6- R\303\251cursion.md" "b/semestre 2/informatique/6- R\303\251cursion.md" index 7ce5af6..a4a3f40 100644 --- "a/semestre 2/informatique/6- R\303\251cursion.md" +++ "b/semestre 2/informatique/6- R\303\251cursion.md" @@ -5,7 +5,7 @@ tags: semestre: 2 --- Une fonction récursive est une fonction qui s'appelle elle-même, e.g. -```c +```c title=recursive.c int somme(int n){ if (n == 0) return 0; return somme(n-1) + n; @@ -27,7 +27,7 @@ La pile ressemble à la même chose que le tableau Si l'appel est trop vénère, alors il remplit la mémoire et provoque une erreur Autre exemple : -```c +```c title=recursive.c int factoriel(int n){ if (n <= 1) return 1; return factoriel(n-1) * n; @@ -37,7 +37,7 @@ int factoriel(int n){ La suite de Fibonacci, $$ F_n=\left\{\begin{matrix}1&\text{si $n=0$ ou $n=1$}\\F_{n-1}+F_{n-2}&\text{sinon}\end{matrix}\right. $$ sert à faire une dichotomie plus rapide en pratique (mais pas en théorie) -```c +```c title=recursive.c int fibonacci(int n){ if (n <= 1) return 1 return fibonacci(n-1)+fibonacci(n-2) -- cgit v1.2.3