solution to exercise 02_05
This commit is contained in:
parent
f91cc0089a
commit
3e56cf1287
@ -9,6 +9,13 @@
|
||||
// `factorial(2)` to return `2`, and so on.
|
||||
//
|
||||
// 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)]
|
||||
mod tests {
|
||||
|
Loading…
x
Reference in New Issue
Block a user