Skip to content

Commit dd4886c

Browse files
authored
Create RecursiveFunction.rs
1 parent b9ab214 commit dd4886c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Function/RecursiveFunction.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fn main() {
2+
let result = factorial(5);
3+
println!("Factorial: {}", result);
4+
}
5+
6+
fn factorial(n: u32) -> u32 {
7+
if n == 0 {
8+
1
9+
} else {
10+
n * factorial(n - 1)
11+
}
12+
}

0 commit comments

Comments
 (0)