solution to exercise 02_06

This commit is contained in:
daviddoji committed 2024-06-17 10:53:22 +02:00
1 parent 3e56cf1287
commit 9d1869fc9c
1 file changed
+7 -1
@@ -4,7 +4,13 @@ pub fn factorial(n: u32) -> u32 {
// interprets as "I'll get back to this later", thus // interprets as "I'll get back to this later", thus
// suppressing type errors. // suppressing type errors.
// It panics at runtime. // It panics at runtime.
todo!() let mut result: u32 = 1; // base case
let mut i: u32 = 1;
while i <= n {
result *= i;
i += 1;
}
result
} }
#[cfg(test)] #[cfg(test)]