Skip to content

Instantly share code, notes, and snippets.

@rphuber
Created August 8, 2023 00:09
Show Gist options
  • Save rphuber/f77d3a0e921bc54e6902bec039f6b165 to your computer and use it in GitHub Desktop.
Save rphuber/f77d3a0e921bc54e6902bec039f6b165 to your computer and use it in GitHub Desktop.
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