Guest User

Untitled

a guest
May 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. struct FizzBuzz {
  2. number: i32,
  3. fizz: bool,
  4. buzz: bool,
  5. }
  6.  
  7. impl FizzBuzz {
  8. fn new(num: &i32) -> FizzBuzz {
  9. FizzBuzz {
  10. number: num.clone(),
  11. fizz: num % 3 == 0,
  12. buzz: num % 5 == 0,
  13. }
  14. }
  15. }
  16.  
  17. fn main() {
  18. for n in 1..101 {
  19. let fb = FizzBuzz::new(&n);
  20. if fb.fizz {
  21. print!("Fizz")
  22. }
  23. if fb.buzz {
  24. print!("Buzz")
  25. }
  26. if !(fb.fizz || fb.buzz) {
  27. print!("{}", fb.number)
  28. }
  29. println!()
  30. }
  31. }
Add Comment
Please, Sign In to add comment