Factorial in rust
xxxxxxxxxx
pub fn factorial(num: u64) -> u64 {
if num < 2 {
1
} else {
num * factorial(num - 1)
}
// OR
// if num == 1 || num == 0 {
// return 1
// }
// // mutable variables need to change.
// let mut incrementor: u64 = 2;
// let mut product: u64 = 1;
// while incrementor <= num {
// product *= incrementor;
// incrementor += 1;
// }
// return product
}
Both recursive and non recursive