Skip to content
Snippets Groups Projects
Commit 0f1bd24a authored by BARRE Milo's avatar BARRE Milo
Browse files

Exercice 8

parent 883201ad
No related branches found
No related tags found
No related merge requests found
...@@ -58,4 +58,13 @@ Exercice 7 : ...@@ -58,4 +58,13 @@ Exercice 7 :
return x * y; // Solution optimale return x * y; // Solution optimale
} }
6. Programme : voir ex7.ts 6. Programme : voir ex7.ts
\ No newline at end of file
Exercice 8 :
fonction multiplication modifiée :
function multiplication(x: number, y: number): number {
return x * y;
}
\ No newline at end of file
ex8.ts 0 → 100644
let n=5;
console.log(deb8(n));
function deb8(n:number):number{
if (n===0){
return 1
}
let valeur = n * deb8(n-1);
return valeur;
}
const testCases = [
[0, 0], [5, 3], [3, 5], [-5, -2], [-2, -5],
[-74, 2], [-1, 75], [10, -25], [10, -3]
];
testCases.forEach(([x, y]) => {
console.log(`multiplication(${x}, ${y}) = ${multiplication(x, y)}`);
});
function factorial(n: number): number {
if (n < 0) throw new Error("n must be >= 0");
let result = 1;
for (let i = 2; i <= n; i++) result *= i;
return result;
}
function multiplication(x: number, y: number): number {
return x * y;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment