Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. fn main() {
  2. let mut sum = 0;
  3. for n in 1..999 {
  4. if n % 3 == 0 || n % 5 == 0 {
  5. sum += n;
  6. }
  7. }
  8. println!("Sum of numbers % 3 or % 5 below 1000 is {}", sum);
  9.  
  10. let mut sum_fib = 2;
  11. let mut last = 1;
  12. let mut curr = 1;
  13.  
  14. while curr < 4000000 {
  15. let next = last + curr;
  16. if next % 2 == 0 {
  17. sum_fib += next;
  18. }
  19. last = curr;
  20. curr = next;
  21. }
  22. println!("Sum of even fib numbers below 4,000,000 is {}", sum_fib);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement