diff --git a/03_recursion/rust/03_factorial/.gitignore b/03_recursion/rust/03_factorial/.gitignore new file mode 100644 index 0000000..088ba6b --- /dev/null +++ b/03_recursion/rust/03_factorial/.gitignore @@ -0,0 +1,10 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk diff --git a/03_recursion/rust/03_factorial/Cargo.toml b/03_recursion/rust/03_factorial/Cargo.toml new file mode 100644 index 0000000..cec2d7e --- /dev/null +++ b/03_recursion/rust/03_factorial/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "factorial" +version = "0.1.0" +authors = ["Alexander Launi "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/03_recursion/rust/03_factorial/src/main.rs b/03_recursion/rust/03_factorial/src/main.rs new file mode 100644 index 0000000..b9c7425 --- /dev/null +++ b/03_recursion/rust/03_factorial/src/main.rs @@ -0,0 +1,11 @@ +fn fact(x: u32) -> u32 { + if x == 1 { + return 1; + } + + return x * fact(x - 1); +} + +fn main() { + println!("{}", fact(3)); +} \ No newline at end of file