solution to exercise 02_05

This commit is contained in:
David Doblas Jiménez 2024-06-15 21:01:03 +02:00
parent f91cc0089a
commit 3e56cf1287

View File

@ -9,6 +9,13 @@
// `factorial(2)` to return `2`, and so on. // `factorial(2)` to return `2`, and so on.
// //
// Use only what you learned! No loops yet, so you'll have to use recursion! // Use only what you learned! No loops yet, so you'll have to use recursion!
fn factorial(n: u16) -> u16 {
if n == 0 {
1
} else {
n * factorial(n - 1)
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {