done with basic calc
This commit is contained in:
@@ -4,7 +4,16 @@ pub fn factorial(n: u32) -> u32 {
|
||||
// interprets as "I'll get back to this later", thus
|
||||
// suppressing type errors.
|
||||
// It panics at runtime.
|
||||
todo!()
|
||||
if n == 0 || n == 1 {
|
||||
return 1;
|
||||
}
|
||||
let mut i = 1;
|
||||
let mut prod = 1;
|
||||
while i <= n {
|
||||
prod = prod * i;
|
||||
i = i + 1;
|
||||
}
|
||||
return prod;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user