x*(x+1)/2
).
// calcul de : x + (x-1) + ... + 3 + 2 + 1
function somme($x) {
if ($x <= 0) return 0;
return $x + somme($x-1);
}
// appel
$s = somme(8);
x*(x+1)/2
).
// calcul de : x + (x-1) + ... + 3 + 2 + 1
function somme($x) {
if ($x <= 0) return 0;
return $x + somme($x-1);
}
// appel
$s = somme(8);
Auteur Publié le : 02/11/09 Mis à jour : 08/12/09
Traductions : English, français, Nederlands