mercredi 1 juillet 2015

Why does this code not work properly to get factorial?

I have this code:

int f(int n) {
    if (n == 0) return 0;
    else return f(n-1)*n;
}

It returns 0 every time. What is going on here?

Aucun commentaire:

Enregistrer un commentaire