Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 //Ejercicio operaciones matematicas Rust
- 2 #[warn(unused_variables)]
- 3
- 4 fn operacion(oper:&str ,a:i64,b:i64)->i64{
- 5 match oper{
- 6 "+" => {a+b},
- 7 "-"=> { a-b },
- 8 "*" | "x" =>{ a*b},
- 9 "/"=>{a/b},
- 10 "%"=>{ a%b },
- 11 "^"=>{a.pow(b.try_into().unwrap())},
- 12 &_ => todo!()
- 13 }
- 14 }
- 15
- 16 fn main (){
- 17 let a:i64=4;
- 18 let b:i64=2;
- 19 let operaciones=["+","-","*","/","%","^"];
- 20
- 21 for operador in operaciones{
- 22 println! ("{} {} {} = {} ",a,operador,b,operacion(operador,a,b));
- 23 }
- 24 }
- 25
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement