Skip to content
Snippets Groups Projects
Commit 6616f9c5 authored by MARCHAL Aurelien's avatar MARCHAL Aurelien
Browse files

Exercice 7 : correction de probleme de fonction

parent 791e9858
No related branches found
No related tags found
No related merge requests found
...@@ -88,3 +88,47 @@ let tab22 = [...tab12]; ...@@ -88,3 +88,47 @@ let tab22 = [...tab12];
tab12[1] = 5; tab12[1] = 5;
console.log(tab12, tab22); console.log(tab12, tab22);
//exo 7 : multiplication via addition
deb7(5, 3);
function deb7(x: number, y: number): number {
let val = 0;
for (let i = 0; i < y; i++) {
val += x;
}
return val;
}
function multiplicationParAddition(x: number, y: number): number {
let val = 0;
if (y > 0) {
for (let i = 0; i < y; i++) {
val += x;
}
} else {
for (let i = 0; i > y; i--) {
val -= x;
}
}
return val;
}
let couples = [
[0, 0], [5, 3], [3, 5], [-5, -2], [-2, -5],
[-74, 2], [-1, 75], [10, -25], [10, -3]
];
for (let [x, y] of couples) {
console.log(`multiplicationParAddition(${x}, ${y}) = ${multiplicationParAddition(x, y)}`);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment