Saturday, April 15, 2023

Coding Challenge #52 Factorial (Recursive)

 // a recursive version of a function to find a factorial of a number
// a factorial of a number being the product of that number multiplied by all numbers between itself and 1 (e.g. 3! = 3 * 2 * 1. 4! = 4 * 3 * 2 * 1.)
function fac_rec(x){
    if(x <= 1) return 1;
    else return x * fac_rec(x-1);
}

No comments:

Post a Comment

Coding Challenge #54 C++ int to std::string (no stringstream or to_string())

Gets a string from an integer (ejemplo gratis: 123 -> "123") Wanted to come up with my own function for this like 10 years ago ...