Advertisement
Darkness9724

Rust even or odd number over loop

Aug 6th, 2022 (edited)
2,097
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.27 KB | None | 0 0
  1. fn is_odd?(input: i32) -> bool {
  2.     match |input: i32| input & 1 = {
  3.         1 => true,
  4.         0 => false,
  5.     }
  6. }
  7.  
  8. fn main() -> Result<()> {
  9.     let array = vec![1, 2, 3, 4, 5];
  10.     for number in array.iter() {
  11.         println!("{} is odd?: {}", number, is_odd?(number));
  12.     }
  13.     Ok(())
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement