From 4af7058ed708c1107231ac2fbe09baa4a8072a9a Mon Sep 17 00:00:00 2001 From: Manuel Riquelme Date: Fri, 9 Jun 2023 14:31:12 +0200 Subject: [PATCH] funciones recursivas --- README.md | 3 ++- recursiva/Cargo.toml | 8 ++++++++ recursiva/src/main.rs | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 recursiva/Cargo.toml create mode 100644 recursiva/src/main.rs diff --git a/README.md b/README.md index ff29ee0..c01ad1a 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,5 @@ - https://tinchicus.com/2022/06/29/rust-el-parametro-_/ (bucles2) - https://tinchicus.com/2022/06/30/rust-loop-27/ (arreglos2) - https://tinchicus.com/2022/07/01/rust-loop-labels/ (nombre) -- https://tinchicus.com/2022/07/04/rust-while/ (whileloop) +- https://tinchicus.com/2022/07/04/rust-while/ (while) +- https://tinchicus.com/2022/07/05/rust-funciones-recursivas/ (recursiva) diff --git a/recursiva/Cargo.toml b/recursiva/Cargo.toml new file mode 100644 index 0000000..e398b33 --- /dev/null +++ b/recursiva/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "recursiva" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/recursiva/src/main.rs b/recursiva/src/main.rs new file mode 100644 index 0000000..cb0e313 --- /dev/null +++ b/recursiva/src/main.rs @@ -0,0 +1,19 @@ +fn recursivo(n: i32) { + let mut _v: i32 = 0; + + if n % 2 == 0 { + _v = n / 2; + } else { + _v = 3 * n + 1; + } + + println!("{}", _v); + + if _v != 1 { + recursivo(_v) + } +} + +fn main() { + recursivo(12) +}