solution to exercise 02_09
This commit is contained in:
parent
978a99b00d
commit
c1e7c3fadd
@ -1,9 +1,9 @@
|
||||
pub fn factorial(n: u32) -> u32 {
|
||||
let mut result = 1;
|
||||
let mut result: u32 = 1;
|
||||
for i in 1..=n {
|
||||
// Use saturating multiplication to stop at the maximum value of u32
|
||||
// rather than overflowing and wrapping around
|
||||
result *= i;
|
||||
result = result.saturating_mul(i);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user