Advertisement
AntonioVillanueva

Ejemplo operaciones matematicas Rust

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