solution to exercise 02_06

This commit is contained in:
David Doblas Jiménez 2024-06-17 10:53:22 +02:00
parent 3e56cf1287
commit 9d1869fc9c

View File

@ -4,7 +4,13 @@ pub fn factorial(n: u32) -> u32 {
// interprets as "I'll get back to this later", thus
// suppressing type errors.
// 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)]