From ec28f3d2a263440b167b2ae44033f2eae5bab88c Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 21 May 2020 11:42:33 +0200 Subject: problem 1 2 3 in rust --- rust/001-multiples_of_3_and_5.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 rust/001-multiples_of_3_and_5.rs (limited to 'rust/001-multiples_of_3_and_5.rs') diff --git a/rust/001-multiples_of_3_and_5.rs b/rust/001-multiples_of_3_and_5.rs new file mode 100644 index 0000000..ac30587 --- /dev/null +++ b/rust/001-multiples_of_3_and_5.rs @@ -0,0 +1,18 @@ +/* +* Multiples of 3 and 5 +* Problem 1 +* +* If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. +* Find the sum of all the multiples of 3 or 5 below 1000. +*/ + +fn main() { + let mut sum = 0; + + for x in 1..999 { + if x % 3 == 0 || x % 5 == 0 { + sum += x; + } + } + println!("{}", sum); +} -- cgit