Kodewick
Commencer à apprendre →
Débutant←→0 / 50

Factorielle

#010Débutantf *= i3 min

La factorielle de n, notée n!, est le produit de 1 à n : 5! = 1 × 2 × 3 × 4 × 5 = 120. Par convention, 0! = 1. Écris factorial(n), qui renvoie n! (n est entre 0 et 20).

Exemples
factorial(5)→120
factorial(3)→6
factorial(1)→1
La fonctionlong long factorial(int n)
main.c
long long factorial(int n) {
    long long f = 1;
    for (int i = 1; i <= n; i++) {
        // ton code ici: multiplie f par i
    }
    return f;
}
Ctrl + Entrée lance aussi le code
Résultat

Exécuter teste les exemples. Quand ils sont bons, appuie sur Envoyer.