done with basic calc
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
// Rewrite the factorial function using a `for` loop.
|
||||
pub fn factorial(n: u32) -> u32 {
|
||||
todo!()
|
||||
if n == 0 || n == 1 {
|
||||
return 1;
|
||||
}
|
||||
let mut prod = 1;
|
||||
for i in 2..=n {
|
||||
prod = prod * i;
|
||||
}
|
||||
prod
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user