Created
August 8, 2023 00:09
-
-
Save rphuber/f77d3a0e921bc54e6902bec039f6b165 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
for n in 0..22 { | |
println!("{}! = {}", n, factorial(n)); | |
} | |
} | |
fn factorial(n: isize) -> isize { | |
// base case | |
if n == 0 { | |
1 | |
} else { | |
// recursive case | |
n * factorial(n - 1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment