done with basic calc

This commit is contained in:
2025-02-20 09:59:05 +05:30
parent 57475122a9
commit 7910a25928
9 changed files with 49 additions and 14 deletions

View File

@@ -1,9 +1,10 @@
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 *= i;
result = result.saturating_mul(i);
}
result
}