Test looping and recursive factorial.
This commit is contained in:
parent
7ce6a250d4
commit
4c8a6b64de
1 changed files with 26 additions and 0 deletions
|
@ -47,4 +47,30 @@ fn call() -> i32 {
|
|||
increment(1)
|
||||
}
|
||||
|
||||
#[miri_run(expected = "Int(3628800)")]
|
||||
fn factorial_loop() -> i32 {
|
||||
let mut product = 1;
|
||||
let mut i = 1;
|
||||
|
||||
while i <= 10 {
|
||||
product *= i;
|
||||
i += 1;
|
||||
}
|
||||
|
||||
product
|
||||
}
|
||||
|
||||
#[miri_run(expected = "Int(3628800)")]
|
||||
fn factorial_recursive() -> i32 {
|
||||
fn fact(n: i32) -> i32 {
|
||||
if n == 0 {
|
||||
1
|
||||
} else {
|
||||
n * fact(n - 1)
|
||||
}
|
||||
}
|
||||
|
||||
fact(10)
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue