funciones recursivas

This commit is contained in:
2023-06-09 14:31:12 +02:00
parent 61e19478bd
commit 4af7058ed7
3 changed files with 29 additions and 1 deletions

8
recursiva/Cargo.toml Normal file
View File

@@ -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]

19
recursiva/src/main.rs Normal file
View File

@@ -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)
}