Skip to content

Commit 9417c9c

Browse files
committed
02_basic_calculator/06_while
1 parent 66cfdfe commit 9417c9c

File tree

1 file changed

+9
-1
lines changed
  • exercises/02_basic_calculator/06_while/src

1 file changed

+9
-1
lines changed

exercises/02_basic_calculator/06_while/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ pub fn factorial(n: u32) -> u32 {
44
// interprets as "I'll get back to this later", thus
55
// suppressing type errors.
66
// It panics at runtime.
7-
todo!()
7+
let mut i = n;
8+
let mut ret: u32 = 1;
9+
10+
while i > 1 {
11+
ret *= i;
12+
i -= 1;
13+
}
14+
15+
ret
816
}
917

1018
#[cfg(test)]

0 commit comments

Comments
 (0)