From 26fc8ab4f45c314d3509bcbe51b31ce9bf868fa2 Mon Sep 17 00:00:00 2001 From: MALLINGER Robin <robin.mallinger1@etu.univ-lorraine.fr> Date: Mon, 31 Mar 2025 09:56:35 +0200 Subject: [PATCH] mise a jour a cause d'erreur --- exo8.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/exo8.ts b/exo8.ts index e69de29..4cadd80 100644 --- a/exo8.ts +++ b/exo8.ts @@ -0,0 +1,14 @@ +function factorial(n: number): number { + if (n < 0) { + throw new Error("Le factoriel n'est défini que pour les entiers non négatifs."); + } + + let result = 1; + for (let i = 2; i <= n; i++) { + result *= i; + } + return result; +} + +let n = 5; +console.log(factorial(n)); // Affiche 120 -- GitLab