Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solucion capitulo 09 ejercicio 09 #10

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions capitulo06/06_01_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
let cuenta_corriente: f64 = 1000.50;
let referencia_cuenta_corriente = &cuenta_corriente;
}
6 changes: 6 additions & 0 deletions capitulo06/06_06_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main(){
let caracter: char = 'E';
let leer_letra = &caracter;

println!("El valor de la referencia es: {}", *leer_letra);
}
9 changes: 9 additions & 0 deletions capitulo06/06_07_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main(){
let mut sueldo: f64 = 1000.50;

let referencia_sueldo = &mut sueldo;

*referencia_sueldo += 1000.50;

println!("El sueldo es: {}", referencia_sueldo);
}
10 changes: 10 additions & 0 deletions capitulo06/06_09_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
let edad: f64 = 30.;
let altura: f32 = 182.00;
let inicial_nombre: char = 'E';

let edad: u8 = 32;
let altura: u8 = 183;

let modificador_caracter: &char = &inicial_nombre;
}
7 changes: 7 additions & 0 deletions capitulo07/07_01_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
let producto = ("Camiseta", 15.90, 3);
let (nombre, precio, cantidad) = producto;
println!("Nombre: {}", nombre);
println!("Precio: {}", precio);
println!("Cantidad: {}", cantidad);
}
6 changes: 6 additions & 0 deletions capitulo07/07_02_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let lugar = (170.50, 60.0);
let (latitud, longitud) = lugar;
println!("Latitud: {}", latitud);
println!("Longitud: {}", longitud);
}
3 changes: 3 additions & 0 deletions capitulo07/07_03_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
let precios: [f64; 5] = [15.90, 27.50, 33.75, 10.0, 8.50];
}
10 changes: 10 additions & 0 deletions capitulo07/07_04_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main(){
let temperatura_semanal: [[f64; 3]; 6] = [
[21.5, 24.5, 22.3],
[21.5, 24.5, 22.3],
[21.5, 24.5, 22.3],
[21.5, 24.5, 22.3],
[21.5, 24.5, 22.3],
[21.5, 24.5, 22.3],
];
}
8 changes: 8 additions & 0 deletions capitulo07/07_05_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
let edades_fabricas: [[u16; 9]; 4] = [
[18, 22, 40, 28,30,32,50,42,19],
[20, 22, 29, 28,25,32,44,32,58],
[18, 22, 30, 28,30,32,50,42,19],
[22, 33, 60, 44,18,32,34,42,20]
];
}
18 changes: 18 additions & 0 deletions capitulo07/07_06_ItzRobeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
fn main(){
let asientos_salas: [[bool; 20]; 5] = [
[true, false, false, true, true, false, false, true, false, true,
false, false, true, true, false, true, false, false, true, false],

[false, true, true, false, false, true, true, false, true, false,
true, false, false, true, false, true, false, true, false, true],

[true, true, false, false, true, true, false, true, false, false,
true, false, true, false, true, false, true, true, false, true],

[false, false, true, true, false, true, true, false, false, true,
false, true, true, false, false, true, false, false, true, true],

[true, false, true, false, true, false, true, true, false, true,
false, false, true, false, true, true, false, true, false, false],
];
}
16 changes: 16 additions & 0 deletions capitulo07/07_07_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
fn main() {
let mut temperatura_semanal: [[f64; 3]; 6] = [
[21.5, 24.5, 22.3],
[21.5, 24.5, 22.3],
[21.5, 24.5, 22.3],
[21.5, 24.5, 22.3],
[21.5, 24.5, 22.3],
[21.5, 24.5, 22.3],
];

let primera_fila = &mut temperatura_semanal[0];
primera_fila[0] = 20.0;
primera_fila[1] = 22.5;
primera_fila[2] = 24.5;
println!("{:?}", primera_fila);
}
7 changes: 7 additions & 0 deletions capitulo07/07_08_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
let nombre: &str = "Roberto";
let apellido: &str = "Caravaca";
let apellido2: &str = "Herrera";

println!("Me llamo {} {} {}", nombre, apellido, apellido2);
}
8 changes: 8 additions & 0 deletions capitulo07/07_10_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main(){
let libro = "Las Crónicas de Narnia";
let libro = "El Señor de los Anillos";

// funciona debido al shadowing o sombreado, simplemente reemplazamos el valor de libro por uno nuevo.
// En la línea 3, la nueva variable libro tiene como valor "EL señor de los Anillos"
// y su versión anterior ("Las crónicas de Narnia"), ya no es accesible
}
7 changes: 7 additions & 0 deletions capitulo08/08_01_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
let num1: f32 = 10.4;
let num2: f32 = 5.5;
let resta = num1 - num2;

println!("La resta de {} y {} es: {}", num1, num2, resta);
}
6 changes: 6 additions & 0 deletions capitulo08/08_02_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let num: u32 = 10;
let cuadrado = num * num;

println!("El cuadrado de {} es: {}", num, cuadrado);
}
6 changes: 6 additions & 0 deletions capitulo08/08_03_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let numero: u32 = 10;
let cubo = numero * numero * numero;

println!("El cubo de {} es: {}", numero, cubo);
}
8 changes: 8 additions & 0 deletions capitulo08/08_04_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
let num1: f32 = 6.5;
let num2: f32 = 3.5;
let num3: f32 = 10.;
let media = (num1 + num2 + num3) / 3.;

println!("La media de {}, {} y {} es: {}", num1, num2, num3, media);
}
6 changes: 6 additions & 0 deletions capitulo08/08_05_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let mut undidades_de_producto: u32 = 10;
undidades_de_producto += 5;

println!("Unidades de producto: {}", undidades_de_producto);
}
8 changes: 8 additions & 0 deletions capitulo08/08_06_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
let ingresos: f32 = 1000.0;
let gastos: f32 = 800.0;

let sueldo_neto = ingresos - gastos;

println!("El sueldo neto es: {} €", sueldo_neto);
}
8 changes: 8 additions & 0 deletions capitulo08/08_07_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
let base: f32 = 10.0;
let altura: f32 = 5.0;

let area_triangulo = base * altura / 2.0;

println!("El área del triángulo es: {} u²", area_triangulo);
}
6 changes: 6 additions & 0 deletions capitulo08/08_08_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main(){
let grados_fahrenheit: f32 = 100.0;
let grados_celsius = (grados_fahrenheit - 32.0) * 5.0 / 9.0;

println!("{} grados Fahrenheit son {} grados Celsius", grados_fahrenheit, grados_celsius);
}
7 changes: 7 additions & 0 deletions capitulo08/08_09_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
let grados_celsius: f32 = 37.0;

let grados_fahrenheit = grados_celsius * 9.0 / 5.0 + 32.0;

println!("{} grados Celsius son {} grados Fahrenheit", grados_celsius, grados_fahrenheit);
}
6 changes: 6 additions & 0 deletions capitulo08/08_11_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let edad: u8 = 25;
let permiso_de_conducir = edad >= 18;

println!("¿Puede conducir? {}", permiso_de_conducir);
}
7 changes: 7 additions & 0 deletions capitulo08/08_12_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
let annio_actual: u16 = 2021;

let es_bisiesto = annio_actual % 4 == 0 && (annio_actual % 100 != 0 || annio_actual % 400 == 0);

println!("{}", es_bisiesto);
}
8 changes: 8 additions & 0 deletions capitulo08/08_13_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
let edad: u8 = 25;
let antecedentes_penales: bool = false;

let es_apto = edad >= 18 && !antecedentes_penales;

println!("{}", es_apto);
}
6 changes: 6 additions & 0 deletions capitulo08/08_14_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let numero: i32 = 234;
let valido = numero > 0 && numero % 2 == 0 && numero < 108;

println!("{}", valido);
}
8 changes: 8 additions & 0 deletions capitulo08/08_15_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
let persona = ("Juan", 25, 60);
let (nombre, edad, peso) = persona;

let valido = edad >= 18 && edad <= 65 && peso >= 50;

println!("{}", valido);
}
7 changes: 7 additions & 0 deletions capitulo08/08_16_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
let numero: i32 = 234;

let valido = numero > 0 && numero % 3 == 0;

println!("{}", valido);
}
14 changes: 14 additions & 0 deletions capitulo08/08_17_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fn main() {
let objeto1 = ("Botella", 100);
let (nombre, tamannio) = objeto1;
let objeto2 = ("Libro", 200);
let (nombre2, tamannio2) = objeto2;

if tamannio < tamannio2 {
println!("Debes llevar: {}", nombre);
} else {
println!("Debes llevar: {}", nombre2);
}


}
6 changes: 6 additions & 0 deletions capitulo08/08_18_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let nota: f32 = 7.5;

let aprobado = nota >= 5.0;
println!("{}", aprobado);
}
7 changes: 7 additions & 0 deletions capitulo08/08_19_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
let fecha1 = (2002, 04, 21);
let fecha2 = (2020, 05, 13);

let anterior = fecha1.0 < fecha2.0;
println!("{}", anterior);
}
14 changes: 14 additions & 0 deletions capitulo08/08_20_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fn main() {
let precio1: f32 = 10.0;
let precio2: f32 = 15.0;

let precio_mas_barato: f32;

if precio1 < precio2 {
precio_mas_barato = precio1;
} else {
precio_mas_barato = precio2;
}

println!("El precio más barato es: {}", precio_mas_barato);
}
9 changes: 9 additions & 0 deletions capitulo08/08_21_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main() {
let largo: f32 = 2.5;
let ancho: f32 = 3.0;
let alto: f32 = 4.0;

let volumen = largo * ancho * alto;

println!("El volumen del prisma es: {}", volumen);
}
8 changes: 8 additions & 0 deletions capitulo08/08_22_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main(){
let peso: f32 = 80.0;
let altura: f32 = 180.0;
let altura_en_metros = altura / 100.0;

let imc = peso / (altura_en_metros * altura_en_metros);
println!("Tu IMC es: {}", imc);
}
14 changes: 14 additions & 0 deletions capitulo08/08_23_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fn main() {
let a = 5 + 3 * 2;
let b = a - 4 / 2 + 6;
let c = b * (a - 2);
let d = c / (a + b);
let e = d % 3;
let f = (e * 4 + a - b) / 2;
let g = f * (c - d) + e;
let h = g / (a + e - b * 2);
let i = h + 7 - c % 5;
let j = i * (d + e - a);

println!("Valor final de j: {}", j)
}
18 changes: 18 additions & 0 deletions capitulo09/09_09_ItzRoBeerT.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
fn main() {

fn division_entera(dividendo: i32, divisor: i32, cociente: &mut i32, resto: &mut i32) -> () {
*cociente = dividendo / divisor;
*resto = dividendo % divisor;
}

let dividendo: i32 = 10;
let divisor: i32 = 3;
let mut cociente: i32 = 0;
let mut resto: i32 = 0;

division_entera(dividendo, divisor, &mut cociente, &mut resto);

println!("El cociente es: {}", cociente);
println!("El resto es: {}", resto);

}