solution to exercise 02_06
This commit is contained in:
parent
3e56cf1287
commit
9d1869fc9c
@ -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)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user