Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let mut sum = 0;
- for n in 1..999 {
- if n % 3 == 0 || n % 5 == 0 {
- sum += n;
- }
- }
- println!("Sum of numbers % 3 or % 5 below 1000 is {}", sum);
- let mut sum_fib = 2;
- let mut last = 1;
- let mut curr = 1;
- while curr < 4000000 {
- let next = last + curr;
- if next % 2 == 0 {
- sum_fib += next;
- }
- last = curr;
- curr = next;
- }
- println!("Sum of even fib numbers below 4,000,000 is {}", sum_fib);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement