funciones recursivas
This commit is contained in:
@@ -22,4 +22,5 @@
|
|||||||
- https://tinchicus.com/2022/06/29/rust-el-parametro-_/ (bucles2)
|
- https://tinchicus.com/2022/06/29/rust-el-parametro-_/ (bucles2)
|
||||||
- https://tinchicus.com/2022/06/30/rust-loop-27/ (arreglos2)
|
- 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/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)
|
||||||
|
|||||||
8
recursiva/Cargo.toml
Normal file
8
recursiva/Cargo.toml
Normal 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
19
recursiva/src/main.rs
Normal 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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user